👀 Live Preview
Pre-checked newsletter checkbox:

The checked attribute is a fundamental feature in HTML, primarily associated with <input> elements of type checkbox or radio. It allows developers to preselect these controls so they appear selected when the page loads.
Presence = on.
Opt-in defaults.
One per group.
Always pair.
JS property.
Initial state.
checkedThe primary purpose of the checked attribute is to set the initial state of a checkbox or radio button. When the attribute is present, the control is selected by default when the page loads. This is useful for newsletter opt-ins, remembered preferences, or a default choice in a radio group.
Checkboxes can have multiple selections. Radio buttons with the same name form a group where only one can be selected at a time—mark only one radio as checked by default.
Add the boolean checked attribute to a checkbox or radio input:
<input type="checkbox" id="subscribe" name="subscribe" checked>
<label for="subscribe">Subscribe to newsletter</label>input type="checkbox" and input type="radio".checked="false"—any value still checks the box in HTML.<label for="...">.name within a group and check only one by default.The checked attribute is a boolean attribute, meaning it does not require a value. It can be present or absent:
<!-- Checked by default -->
<input type="checkbox" checked>
<!-- Unchecked (omit checked) -->
<input type="checkbox">
<!-- Wrong: still checked in HTML -->
<input type="checkbox" checked="false">| Use Case | Markup | Notes |
|---|---|---|
| Newsletter opt-in | <input type="checkbox" checked> | Pre-checked subscription |
| Default radio choice | <input type="radio" name="plan" checked> | One checked per name group |
| Toggle in JS | input.checked = true | Current selection state |
| Reset to initial | input.defaultChecked | Original HTML default |
| Uncheck in JS | input.checked = false | Do not use removeAttribute alone |
| Applicable types | checkbox, radio | Not for text, email, etc. |
| Element / Type | Supported? | Notes |
|---|---|---|
<input type="checkbox"> | Yes | Most common use |
<input type="radio"> | Yes | One checked per name group |
<input type="text"> | No | Use value instead |
<select> / <option> | No | Use selected on <option> |
<button> | No | Not a valid target |
Checkbox example with checked and dynamic JavaScript .checked property.
Pre-checked newsletter checkbox:
Let’s explore a simple example of using the checked attribute with a checkbox:
<input type="checkbox" id="subscribe" name="subscribe" checked>
<label for="subscribe">Subscribe to newsletter</label>In this example, the checkbox has the checked attribute present, indicating that it should be checked by default when the page loads.
You can also dynamically set or remove the checked state using JavaScript. Use the .checked property rather than setting the attribute to false:
<input type="checkbox" id="dynamicCheckbox">
<script>
// Set the checkbox to be checked dynamically
document.getElementById("dynamicCheckbox").checked = true;
</script>In this script, the checked property is set to true for the checkbox with id dynamicCheckbox. This updates the current selection state and is the preferred way to toggle checkboxes at runtime.
<label> so assistive tech announces the purpose.<fieldset> with a <legend>.Include the boolean checked attribute on a checkbox or radio input.
The control appears checked when the page loads.
Clicking changes the current state; radios in a group deselect siblings.
On submit, checked controls include their name and value in form data.
The checked attribute is universally supported on checkbox and radio inputs in all modern browsers.
Checkbox and radio checked works consistently across all browsers.
Bottom line: Use checked confidently on checkbox and radio inputs in all projects.
checked for sensible default selections<label>name group by defaultelement.checked in JavaScriptfieldset and legend for radio groupschecked="false" expecting uncheckedchecked attribute to set the initial state of checkboxes or radio buttons when you want them selected by default.checked property.checked is specific to checkboxes and radio buttons. For other input types, use alternative attributes such as value or selected.The checked attribute is a simple yet powerful tool for controlling the initial state of checkboxes and radio buttons in HTML. It sets user expectations and can streamline common form flows.
By understanding boolean syntax, radio group rules, and the JavaScript checked property, you can enhance the default behavior of your forms and improve user experience.
checkedBookmark these before building HTML forms.
Presence = on.
SyntaxMulti select.
TypeOne per name.
GroupJS toggle.
ScriptAlways pair.
A11ytype="checkbox" and type="radio" only.checked means selected. Omit the attribute or set element.checked = false in JavaScript.element.checked = true or false. This is the preferred API for runtime changes.defaultChecked reflects the original HTML default. checked reflects the current state, which may change after user interaction.selected attribute on <option> elements instead.Practice the checked attribute on a newsletter checkbox and toggle selection dynamically with JavaScript.
5 people found this page helpful