“Checked” inputs and attribute minimization
I was recently sent this question:
I tried to use the following code in an XHTML page. When I validated the page, this showed up as invalid. Why?
<input name="name" type="checkbox" checked />
Answer:
The use of “checked” in this way is referred to as “attribute minimization”. This means the author has used the attribute’s name but has not specifying a value.
For a document to be valid XHTML, attributes cannot be minimized. The W3C XHTML 1.0 spec states:
XML does not support attribute minimization. Attribute-value pairs must be written in full. Attribute names such as compact and checked cannot occur in elements without their value being specified.
So, the correct way to write this code would be:
<input name="name" type="checkbox" checked=”checked” />
Other examples include:
selected="selected"
compact=”compact”
wrap=”wrap”
nowrap=”nowrap”

June 18th, 2008
2:29 am
Permalink
disabled=”disabled”
June 19th, 2008
5:34 pm
Permalink
or even ‘compact=”compact”‘ - I know I’m feeling rather ‘complact’ this morning…
June 19th, 2008
5:49 pm
Permalink
@Stuart: ahhhhhhh! thanks for picking that up