SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: attributes not in key="value" format

  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,252
    Mentioned
    0 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
    SitePoint Award Recipient xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,238
    Mentioned
    51 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.
    };-) http://www.xhtmlcoder.com/
    Thinking Web: Voices of the Community

    > March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?

  3. #3
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    19,896
    Mentioned
    216 Post(s)
    Tagged
    2 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
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,989
    Mentioned
    41 Post(s)
    Tagged
    1 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
    15,805
    Mentioned
    8 Post(s)
    Tagged
    0 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
    i want cake and cookies Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    9,989
    Mentioned
    41 Post(s)
    Tagged
    1 Thread(s)
    Yes, by HTML5 I did mean the non-XML variant.

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

  8. #8
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,666
    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
  •