Coding HTML Attributes

An attribute is a named property associated with an element. In a marked-up document, attributes are coded in a starting tag or standalone tag between the element name and the tag's terminating /> or > delimiter. The code for an HTML attribute consists of the attribute name, an equal sign (=) and the value of the property enclosed in quotes:

<elemname attrname="value">...</elemname>
<elemname attrname="value"/>
Coding Boolean Attributes

Boolean attributes should be coded in their full form using the attribute name in quotes (attribute="attribute") when the value is true and completely omitting the attribute when the value is false. The full form will be properly understood by web browsers parsing polyglot documents with either the HTML syntax or the XML syntax of HTML 5. Avoid using minimized attributes, such as selected, or values with an empty string, such as in selected="", which XPath treats as false rather than true.

<input type="text" readonly="readonly"/>
<input type="text" required="required"/>
<option selected="selected"/>
<video autoplay="autoplay" ...>

WARNING: Be careful when looking for web sites for learning HTML, especially when it comes to things that are treated differently by different browsers. For instance, the examples on some very popular web sites show the value "false" as valid for boolean attributes, which is treated as false by browsers that look at the attribute value and as true by other browsers that only look for the presence or absence of the attribute, resulting in very inconsistent behavior, since that is incorrect coding per the HTML specification:

The values "true" and "false" are not allowed on boolean attributes.

To determine what version of HTML a web page is actually using, enter its URL in the W3C Markup Validation Service and look for the Doctype. If it's not HTML5, change it to HTML5 in the drop-down box and then Revalidate. The pages on this site are Valid HTML 5.