HTML5 Specification :
https://www.w3.org/TR/html5/forms.html#attr-option-selected
The selected attribute is a logical 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 :
<option selected /> <option selected="" /> <option selected="selected" /> <option selected="SeLeCtEd" />
The following are invalid :
<option selected="0" /> <option selected="1" /> <option selected="false" /> <option selected="true" />
Missing an attribute is the only valid syntax for false :
<option />
Recommendation
If you want to write valid XHTML, use selected="selected" since <option selected> not valid XHTML (but valid HTML) and other alternatives are less readable. Otherwise, just use <option selected> as it is shorter.
Ciro Santilli ๅ
ๅญ ้ฒ ๅฎช ๅ
ญๅ ไบไปถ ๆณ่ฝฎๅ
source share