Definition
The checked
attribute is a boolean that specifies whether the <input>
control should be pre-selected.
Applicable Elements
The checked
attribute can be used with the following elements:
HTML <input>
checked
Attribute
The <input>
element is a field used in HTML Forms enabling the user input data.
The checked
attribute is a boolean that specifies whether the <input>
control should be pre-selected. It is used with the radio
and checkbox
<input>
types
.
Syntax
<input type="checkbox" id="name" name="name" checked>
<input type="radio" id="name" name="name" checked>
Usage
- The
checked
attribute is a boolean. - When present, it specifies the
<input>
element’s control should be pre-selected. - It can be used with
<input type="radio">
and<input type="checkbox">
. - The
checked
attribute can be set with JavaScript after the page loads. - The
checked
attribute can be targeted with CSS using the:checked
pseudo-class selector. For instance, you can create elaborate drop-down menus (this website uses it extensively) by targeting thechecked
attribute.
Values
Values can include:
checked
Examples
The following shows a simple form with a radio and checkbox form prefilled with a check.
<form>
<label for="name">Checkbox:</label>
<input type="checkbox" id="name" name="name" checked><br><br>
<label for="name">radio:</label>
<input type="radio" id="name" name="name" checked>
</form>
Specification
The checked
HTML specification for the <input>
element is as follows:
Browser Support
The checked
has the following browser support:
Desktop
Chrome | Edge | Firefox | IE | Opera | Safari | |
---|---|---|---|---|---|---|
<input> | Yes | Yes | Yes | Yes | Yes | Yes |
<element> | Yes | Yes | Yes | Yes | Yes | Yes |
Mobile
Android Webview | Chrome Android | Firefox Android | Opera Android | iOS Safari | Samsung Internet | |
---|---|---|---|---|---|---|
<input> | Yes | Yes | Yes | Yes | Yes | Yes |
<element> | Yes | Yes | Yes | Yes | Yes | Yes |