zoliky — 2013-07-30T09:09:39-04:00 — #1
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?
davemaxwell — 2013-07-30T10:29:18-04:00 — #2
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
felgall — 2013-07-30T15:41:37-04:00 — #3
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.
ralphm — 2013-07-30T21:12:00-04:00 — #4
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.
felgall — 2013-07-30T22:18:08-04:00 — #5
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.
ralphm — 2013-07-30T22:36:23-04:00 — #6
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]
felgall — 2013-07-31T03:17:48-04:00 — #7
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.
stomme_poes — 2013-07-31T08:13:07-04:00 — #8
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.
felgall — 2013-07-31T15:32:24-04:00 — #9
force — 2013-08-01T14:28:40-04:00 — #10
This also applies to the <option> elements and the "selected" attribute.