HTML checked, required and disabled
- type
- boolean attributes
- applies to
- form controls — <input>, <select>, <textarea>, <button>
- lives inside
- the opening tag
- common values
- just the bare word — no ="…" needed
Where it goes
On the field's opening tag, as the bare word: <input type="checkbox" checked>. No equals sign, no quotes.
Example
<input type="checkbox" name="agree" required>
<input type="radio" name="plan" value="pro" checked>
<button disabled>Saving…</button>Open this example in the editor →
Common mistakes
- Writing checked="false" to turn it off. The browser only checks whether the word is there, so that is still checked. Remove the attribute instead.
- Using disabled on a field you still want sent. Disabled fields are dropped. readonly keeps the value and still sends it.
- Trusting required on its own. It is a helpful first check in the browser. Anything that matters must be checked again where the form is received.