A boolean attribute in HTML is an attribute whose presence means true and whose absence means false. You write <input disabled> to disable a field and leave disabled out to enable it. The value does not matter: disabled="false" still disables the element, which is the most common mistake with html boolean attributes.
Boolean attributes control on-off features such as disabled, checked, required, hidden and autoplay.
For a boolean attribute, the browser checks only whether the attribute exists on the element. There are three valid ways to write it:
All three produce a checked checkbox. The first form is the shortest and the most common. If the value is given, it must be either the empty string or the attribute name in ASCII case-insensitive form, such as checked="checked".
Every button above is disabled. To enable a button, remove the attribute completely.
| Attribute | Used on | Meaning |
|---|---|---|
disabled | form controls, <fieldset> | Cannot be used or submitted |
checked | checkbox and radio inputs | Starts selected |
selected | <option> | Starts chosen |
required | form controls | Must be filled before submit |
readonly | text inputs and <textarea> | Visible and submitted, but not editable |
multiple | <input type="file">, <select> | Allows more than one value |
autofocus | form controls and others | Takes focus on load |
hidden | any element | Not rendered |
autoplay, controls, loop, muted | <audio>, <video> | Media behaviour |
open | <details>, <dialog> | Currently expanded or shown |
async, defer | <script> | Script loading behaviour |
novalidate | <form> | Skip built-in validation |
inert | any element | Not interactive |
In JavaScript, most boolean attributes are reflected as properties with true or false values. Properties are the usual way to change them.
Notice that setAttribute("disabled", "false") still disables the element, because the attribute is present. Use removeAttribute("disabled"), the disabled property, or toggleAttribute.
checkedThe checked attribute sets only the default state. After the user clicks the box, the checked property changes, while the attribute stays as it was written. Read input.checked for the current state and use defaultChecked for the initial one.
disabled={isLoading}. A value of false omits the attribute.:disabled="isLoading" works the same way.disabled.Some attributes look boolean but accept specific keywords. These are enumerated attributes, and "false" is a real value for them.
| Attribute | Valid values | Notes |
|---|---|---|
contenteditable | true, false, plaintext-only | An empty value means true |
draggable | true, false | Must be written out |
spellcheck | true, false | Must be written out |
aria-hidden | true, false | ARIA states use strings |
For aria-* attributes, aria-disabled="false" is meaningful and does not turn the state on.
disabled="false" and expecting an enabled control.readonly on a checkbox or select, where it has no effect.hidden and then overriding it with CSS display, which makes it visible again.disabled field to be submitted with the form; disabled controls are left out, while readonly ones are sent.Only the empty string or the attribute's own name is valid, as in checked="" or checked="checked".
Remove it. In JavaScript, set the property to false or call removeAttribute.
A readonly input can be focused and is submitted with the form. A disabled control cannot be focused, is greyed out and is not submitted.
required checked by the browser?Yes. The browser blocks form submission and shows a message unless the form has novalidate. Always validate again on the server.
A boolean attribute is true when present and false when absent, whatever its value. Write it bare, remove it to turn it off, and use JavaScript properties or toggleAttribute instead of setAttribute with a "false" string.