HTML boolean attribute
ID: html-boolean-attribute
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.
New to topics? Read the docs here!