HTML & CSS
Should I use checked or checked="checked" with HTML5?
<input id="male" type="radio" name="genre" value="male" checked />
I read that HTML4 people used to use checked="checked" but it is not required with HTML5 anymore. Is is true?
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/12331290/in-html5-to-set-a-checkbox-as-checked-should-i-simply-use-checked-as-a-proper
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.
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.
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 ...[/ot]
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.
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.
This also applies to the <option> elements and the "selected" attribute.
This topic is now closed. New replies are no longer allowed.