HTML checked Attribute
Description
The HTML checked
attribute is a boolean attribute used primarily with input elements of type checkbox
and radio
. When applied, it specifies that an element should be pre-selected (checked) when the page loads for the first time. This attribute is useful in forms where certain options are recommended or commonly selected by users, allowing web developers to guide user choices or reflect a default state that matches the application's logic or user preferences.
For a checkbox input, the checked
attribute indicates that the checkbox is ticked. For a radio button, it denotes the option that is selected by default out of a group of radio inputs sharing the same name
attribute. It's important to note that for radio buttons, only one option in a given group can be checked
at a time.
The presence of the checked
attribute on an element represents the true state, meaning the element is checked, and its absence represents the false state. Since it's a boolean attribute, its mere presence, regardless of its value, implies a true value. Therefore, writing <input type="checkbox" checked>
is equivalent to <input type="checkbox" checked="checked">
.
This attribute enhances user experience by pre-defining selections that might align with the most common choices, saving users time and simplifying forms. It's also useful for settings pages where the current configuration can be reflected accurately in the form's initial state, showing checkboxes or radio buttons in their appropriate checked or unchecked states based on the user's previous selections or default settings.
Syntax
<input checked> OR <input checked="checked">
Values
- checkedUse 'checked' (without value) or checked='checked'. Both are valid.
Applies To
The checked
attribute can be used on the following html elements.
Example
<form>
<input type="checkbox" id="agree" name="agreement" checked>
<label for="agree">I agree to the terms and conditions.</label>
</form>
Browser Support
The following table will show you the current browser support for the HTML checked
Attribute.
Desktop | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
|
12 | 1 | 1 | 12.1 | 1 |
Tablets / Mobile | |||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
18 | 4 | 12.1 | 1 | 1 | 4.4 |
Last updated by CSSPortal on: 28th March 2024