Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML concept: boolean-attributes

HTML boolean attributes represent true by presence and false only by absence; text that resembles a boolean value does not change that rule.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<button disabled>…</button>

The rule applies only to attributes defined by the standard as boolean, such as disabled, checked, and required; do not generalize it to arbitrary attributes. A reflected IDL property usually exposes the boolean state while the attribute node retains supplied text.

Conforming present forms include disabled="", disabled="disabled", and disabled="DISABLED", because the canonical name is matched ASCII case-insensitively. disabled="false" is nonconforming, but the parser preserves its presence, so the control is still disabled.

To represent false, remove the attribute with removeAttribute("disabled"), toggleAttribute("disabled", false), or the reflected assignment element.disabled = false. Do not write the word false or assume a template or serializer repairs the intent.

The example compares disabled="false", disabled="DISABLED", and disabled="": all three produce a true disabled state. Only assigning false to the property removes the attribute, so the result ends with after=false; present=false.

Examples

<!doctype html>
<meta charset="utf-8">
<button id="a" disabled="false">A</button>
<button id="b" disabled="DISABLED">B</button>
<button id="c" disabled="">C</button>
<output id="result"></output>
<script>
const before = [a.disabled, b.disabled, c.disabled].join(",");
a.disabled = false;
result.textContent = `before=${before}; after=${a.disabled}; present=${a.hasAttribute("disabled")}`;
</script>

Result

before=true,true,true; after=false; present=false

The executed example verifies presence semantics and the boundary between nonconforming value text and actual attribute removal.

Sources