SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    attributes not in key="value" format

    Since when was this OK:

    <input type="checkbox" checked>

    in particular the checked being like that rather than in key="value" format?

    I've never come across that until just recently in starting to learn HTML5 in detail. I've always used XHTML in the past. Is that why
    <input type="checkbox" checked> is so alien to me? Was that kind of thing OK in all previous versions of HTML (not XHTML)? I suspect that's the case.

    Thanks.

  2. #2
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    It is valid in HTML 4.01, and obviously not in XHTML since Attributes may not be minimized in XML. http://www.w3.org/TR/xhtml1/diffs.html#h-4.5. In HTML 4.01, boolean attributes may appear in minimized form - the attribute's value appears alone in the element's start tag.

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    ckecked="checked" ... To quote Jeremy Keith, "This is brought to you by the Department of Redundancy Department". I'm glad that HTML5 has stuck with simple Boolean attributes, like checked, autoplay, controls etc. Much neater.

  4. #4
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    It is of course still okay to use the name-value pairs version in HTML5. The spec allows the shortened version in the cowpaths-paving sense: browsers generally accepted them and honestly don't care; developers care.

    I notice I tend to keep with the key-value pairs for consistency: elements having a mixture of types at least look like they were written by one person :P

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,872
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    In XHTML5 you must use checked="checked" - all versions of XHTML require the long version or you end up with an error in your page and the rest of the page gets chopped off.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    Yes, by HTML5 I did mean the non-XML variant.

  7. #7
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Right, thanks for confirming that.

  8. #8
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <input checked> is equivalent to <input checked=""> i.e. the value is the empty string. The latter syntax is allowed in both HTML and XHTML.

    Also, any attribute may use the minimized form (assuming the empty string is a valid value) in HTML these days, not just boolean attributes.
    Simon Pieters


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •