HTMLInputElement: checked property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thechecked property of theHTMLInputElement interface specifies the current checkedness of the element; that is, whether the form control is checked or not.
The booleanchecked property is relevant to theradio (<input type="radio">) andcheckbox (<input type="checkbox">) input types.
The presence of the HTMLchecked attribute indicates the checkbox is checked by default. It does not indicate whether this checkbox is currently checked: if the checkbox's state is changed, this content attribute does not reflect the change; only theHTMLInputElement'schecked IDL property is updated. Thechecked attribute is reflected by thedefaultChecked property.
When a radio inputchecked property istrue, all other radio inputs with the samename arefalse. If any radio button in a same-named group of radio buttons isrequired, as long as one button in the group ischecked, theValidityState object's read-onlyvalueMissing property for each radio button in the group will befalse.
A checkbox's value is only included in the submitted data upon form submission ifchecked is true. The value of theHTMLInputElement.indeterminate property has no effect on a checkbox'schecked value.
In this article
Value
A boolean.
Examples
const inputElement = document.getElementById("contactMail");console.log(inputElement.checked);inputElement.checked = true;Specifications
| Specification |
|---|
| HTML> # dom-input-checked> |
Browser compatibility
See also
<input>HTMLInputElement.validity:checkedpseudo-class