HTML attribute 2026-11-05
An HTML attribute supplies information about an HTML element, usually through a name and a value in its start tag. Its meaning is defined for the relevant element and attribute. The source notation is converted into attribute data on the element in the Document Object Model.[ref]
HTML Standard by WHATWG. Introduction, attributes in the quick HTML example; HTML syntax, Attributes
For example,
<p id="notice" class="warning">Save</p> gives the paragraph the identifier notice and the class warning. CSS selectors #notice and .warning can then match it for different reasons. The text Save is element content, rather than another attribute value.Some attributes use presence as their boolean signal. For an applicable HTML boolean attribute,
disabled and disabled="false" both express presence; the latter spelling does not make it false. Removing the attribute expresses absence. Treating every value as a programming-language boolean would therefore misread the document.[ref]HTML Standard by WHATWG. Common microsyntaxes, Boolean attributes: presence/absence and permitted values
Attribute data and live interface properties are related by specified reflection rules, not by a universal identity. For some controls, an attribute describes a default while the current state can change through interaction. A JavaScript property access must consequently be interpreted using that interface's definition. This is particularly useful when debugging why the original source and the state a user sees no longer look identical.
HTML boolean attribute 2026-11-05
An HTML boolean attribute represents a two-valued condition through presence or absence. For such an attribute, presence represents true and absence represents false. When present in conforming source, its value is either empty or an ASCII case-insensitive match for the attribute's own name, without surrounding whitespace.[ref]
HTML Standard by WHATWG. Common microsyntaxes, Boolean attributes
For a button's own disabled attribute,
<button disabled> and <button disabled=""> express presence, as does <button disabled="disabled">. Writing disabled="false" does not express absence. Although that value is not a conforming boolean-attribute spelling, the attribute still exists and the browser processes its presence.A program intending to remove the condition can remove the attribute or use the relevant reflected boolean property according to the element's interface. For example,
button.removeAttribute("disabled") removes that attribute. This statement concerns the button's own attribute; an ancestor or other specified control state can separately affect whether the control is effectively disabled.[ref]HTML Standard by WHATWG. Boolean attributes; disabled form controls and reflection rules
Not every attribute with a true-looking value is a boolean attribute. Other attributes use enumerated keywords or other grammars. Defaults and current interaction state can also differ from a serialized attribute, so the rule must be taken from the actual attribute definition. Treating every nonempty attribute as a universal Boolean conversion would erase those distinctions.