What is the correct value for the disabled
attribute for a textbox or textarea?
I've seen the following used before:
<input type="text" disabled />
<input type="text" disabled="disabled" />
<input type="text" disabled="true" />
What is the correct value for the disabled
attribute for a textbox or textarea?
I've seen the following used before:
<input type="text" disabled />
<input type="text" disabled="disabled" />
<input type="text" disabled="true" />
In HTML5, there is no correct value, all the major browsers do not really care what the attribute is, they are just checking if the attribute exists so the element is disabled.
I just tried all of these, and for IE11, the only thing that seems to work is disabled="true". Values of disabled or no value given didnt work. As a matter of fact, the jsp got an error that equal is required for all fields, so I had to specify disabled="true" for this to work.
<input type="text" disabled="disabled" />
is the valid markup.<input type="text" disabled />
is valid and used by W3C on their samples.HTML5 spec:
http://www.w3.org/TR/html5/forms.html#enabling-and-disabling-form-controls:-the-disabled-attribute :
http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes :
Conclusion:
The following are valid, equivalent and true:
The following are invalid:
The absence of the attribute is the only valid syntax for false:
Recommendation
If you care about writing valid XHTML, use
disabled="disabled"
, since<input disabled>
is invalid and other alternatives are less readable. Else, just use<input disabled>
as it is shorter.