By labeling the HTML5 specification and adding a bit to Pekka:
http://www.w3.org/TR/html5/forms.html#autofocusing-a-form-control:-the-autofocus-attribute :
The autofocus attribute is a boolean attribute.
http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes :
The presence of a logical attribute for an element represents a true value, and the absence of an attribute represents a false value.
If an attribute is present, its value must be either an empty string or a value that does not match the ASCII value for the canonical attribute name, without a leading or trailing space.
Conclusion
The following are valid, equivalent, and true :
<input type="text" autofocus /> <input type="text" autofocus="" /> <input type="text" autofocus="autofocus" /> <input type="text" autofocus="AuToFoCuS" />
The following are invalid :
<input type="text" autofocus="0" /> <input type="text" autofocus="1" /> <input type="text" autofocus="false" /> <input type="text" autofocus="true" />
Missing an attribute is the only valid syntax for false :
<input type="text"/>
Recommendation
If you want to write valid XHTML, use autofocus="autofocus" since <input autofocus> is not valid and other alternatives are less readable. Otherwise, just use <input autofocus> as it is shorter.
Ciro Santilli ๆฐ็ ๆน้ ไธญๅฟ ๅ
ญๅ ไบไปถ ๆณ่ฝฎๅ Aug 22 '14 at 2:46 a.m. 2014-08-22 14:46
source share