SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checked or checked="checked" ?

    Should I use checked or checked="checked" with HTML5?

    Code:
    <input id="male" type="radio" name="genre" value="male" checked />
    <label for="male">Male</label>
    I read that HTML4 people used to use checked="checked" but it is not required with HTML5 anymore. Is is true?

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Had to do some research to confirm what I thought, but either are correct. There are some differences that you have to be aware of (css selectors and such), but both are valid.

    Here's a quick link which might explain it a little better: http://stackoverflow.com/questions/1...ed-as-a-proper
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    For HTML 5 use checked and for XHTML 5 use checked="checked"

    Also the /> notation should only be used with XHTML 5 and does not need a space before the / (that was a hack for Netscape 4).

    XHTML 5 does not require a doctype at all since XHTML only has standards mode and the doctype in HTML 5 is there simply to distinguish standards mode from quirks mode and does not identify the version.

    Note that IE8 and earlier do not support XHTML.
    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="^$">

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Off Topic:

    Jeremy Keith makes fun of the checked="checked" syntax by describing it as "brought to you by the Department of Redundancy Department". I thought that was rather funny.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Off Topic:

    Jeremy Keith makes fun of the checked="checked" syntax by describing it as "brought to you by the Department of Redundancy Department". I thought that was rather funny.
    Off Topic:

    I'd have thought checked="yes" and checked="no" would have made more sense given that XHTML requires that all attributes have a value - I guess they did it the way they did for compatibility with HTML.
    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
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Off Topic:

    Quote Originally Posted by felgall View Post
    I'd have thought checked="yes" and checked="no" would have made more sense given that XHTML requires that all attributes have a value - I guess they did it the way they did for compatibility with HTML.
    As Keith says in his little HTML5 book, these Boolean attributes indicate true or false by their very existence or absence respectively, which makes sense to me. He goes on to say that it makes no difference whether you include the value or not (even if you just made up some value of your own, such as checked="yeah baby" [my example]). From the way he words it, adding the value is even optional in XHTML5, though I may be reading it incorrectly, and I'm too lazy to read the specs. Perhaps it would throw a validation error if you didn't do it, though. Meh ...

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Off Topic:


    adding the value is even optional in XHTML5, though I may be reading it incorrectly, and I'm too lazy to read the specs.
    The XML standard requires that all attributes have values so as XHTML is basically HTML redefined according to the XML standard then XHTML 5 as a version of XHTML would be required to have a value specified for all attributres. Whether the browsers actually require it or whether they go ahead and render the page without it is of course a different matter.
    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="^$">

  8. #8
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    Since many of us are using JS to mess with these properties, checked="checked" is easier, because removing attributes is much less fun than simply saying chingie="false".

    Problem is when it's *so* Boolean that thingie="false" returns true simply because it's existing and who cares about values. Then it's FML.

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    Since many of us are using JS to mess with these properties, checked="checked" is easier, because removing attributes is much less fun than simply saying chingie="false".
    Since in JavaScript you specify checked = true and checked = false rather than adding or removing the attribute there is a complete inconsistency between the XHTML value and the JavaScript. Having two separate values for the attribute with one as the default would allow the JavaScript to correspond to the XHTML instead of working completely differently. I suppose that those responsible for XHTML did not consult with those responsible for JavaScript before deciding on their completely inconsistent approach.
    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="^$">

  10. #10
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,516
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by felgall View Post
    For HTML 5 use checked and for XHTML 5 use checked="checked"
    This also applies to the <option> elements and the "selected" attribute.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


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
  •