Alex Rivera | Logout

Why do we need disabled="disabled"?

Asked 2011-06-30T08:03:14.380
43

It seems to be common consensus that for XHTML attributes which do not require any value, we should repeat the attribute name. E.g. <input disabled> in correct XHTML is <input disabled="disabled"/>.

However, we can get the HTML <input> element to be disabled using any of the following:

  • <input disabled=" "/>

  • <input disabled=""/>

  • <input disabled="asdfg">

  • <input disabled="false">

Is there actually an official rule to use disabled="disabled"? Or is it a matter of taste?

Edit
Report

1 Answer

4

@Spudley has already given you the link to the XHTML specs to provide the official documentation.

The choice of making both the attribute and the value the same in XHTML was not entirely arbitrary though.

As @Sohnee says, XHTML 1.0 was a reformulation of HTML4.01 in XML and the goal was to stick to HTML 4 patterns as much as possible to make the transition as easy as possible for web authors.

HTML has always supported disabled="disabled" as a valid form for boolean attributes, and the reason for that is it permitted the shortened attribute disabled to be defined in SGML. (Note @Thaddee Tyl's "bit odd" comment)

In SGML, the disabled on it's own attribute isn't the attribute name without a value, it's the attribute value without a name. i.e. the name is inferred from the value. To make all this work in SGML and be backward compatible with what browsers have always done, the name and the value have to be defined to be the same.

Note that this only affects SGML based validation. Browsers' parser logic isn't SGML based and has never cared for this subtlety, hence you can, in practice put in whatever value for the attribute you like.

HTML5 validation isn't SGML based either, so the restriction has been relaxed. disabled="" is now valid. disabled="true" and disabled="false" are not valid though, because disabled="false" is confusing, since as you note, it disables, not enables the control. See http://www.w3.org/TR/html5/common-microsyntaxes.html#boolean-attributes for details.

answered 2011-06-30T12:08:33.030

Your Answer