The HTML checked attribute
A checkbox or radio button with the HTML checked attribute starts out selected, as in <input type="checkbox" checked>. The attribute sets the default state. Clicks change the checked property instead, and a form reset brings back what the attribute says.
Overview
The HTML checked attribute marks a checkbox or radio button as selected when the page loads. Checkboxes and radio buttons are the two <input> types that carry it. The attribute needs no value, since its presence alone turns the control on.
The attribute holds the default, and the checked property holds the current state. When someone unticks a box that has the attribute, the property turns false but the attribute stays, so outerHTML still shows it. The defaultChecked property reflects the attribute.
Once the user toggles a box, or a script sets its checked property, the attribute only changes the default. Adding or removing it then leaves the tick alone. A form reset puts each box back to what its attribute says and lets the attribute control the state again.
Radio buttons with the same name make up a group when they also share a form, or when none of them has one. Only one button in a group can be checked, and checking one, by a click or from a script, unchecks the others.
Syntax
<label>
<input type="checkbox" name="newsletter" value="weekly" checked>
Send me the weekly newsletter
</label>
Values
| Value |
|---|
| A boolean attribute. If present, the checkbox or radio button starts out checked. |
Example
<form id="prefs">
<label><input type="checkbox" id="news" name="news" value="weekly" checked> Weekly newsletter</label><br>
<label><input type="checkbox" name="offers" value="yes"> Partner offers</label><br>
<label><input type="radio" name="format" value="html" checked> HTML email</label>
<label><input type="radio" name="format" value="text"> Plain text</label><br>
<button type="reset">Reset</button>
<p id="msg" role="status"></p>
</form>
<p>Untick Weekly newsletter, then press Reset.</p>
<script>
const form = document.getElementById('prefs');
const box = document.getElementById('news');
const msg = document.getElementById('msg');
function show() {
const sent = [...new FormData(form)].map(e => e.join('=')).join('&');
msg.textContent = 'Newsletter attribute ' + (box.hasAttribute('checked') ? 'present' : 'absent') +
', property ' + box.checked + '. Form sends ' + (sent || 'nothing') + '.';
}
form.addEventListener('change', show);
form.addEventListener('reset', () => setTimeout(show));
show();
</script>
Best practices
- In most forms, start each radio group with one
checkedbutton. A group with nothing checked is left out of the submitted data. - Wrap each checkbox in a <label>, or link one with
for, so clicking the text toggles the box too. The larger target helps most on small screens such as phones. - Mark a box that must be ticked, such as one confirming the terms, with required. An unticked required box keeps the form from submitting.
- Treat a missing checkbox field as unticked on the server. When a value has to arrive either way, add a hidden input from script.
Accessibility
Let the checked attribute and property carry the state, not ARIA. ARIA in HTML says authors must not put aria-checked on checkbox or radio inputs, because browsers expose the native checked state instead. In Chrome, an unticked box with aria-checked="true" is still exposed as unchecked.
Frequently asked questions
What makes a checkbox checked by default in HTML?
How do I set a checkbox to checked with JavaScript?
box.checked = true, which changes the state without firing a change event. Calling box.click() instead toggles the box and fires click, input and change.Why does setAttribute with checked sometimes not tick the box?
Does checked=false uncheck a checkbox?
Does checked set the default on a radio button as it does on a checkbox?
Which CSS selector matches a checked checkbox?
What does a checked checkbox send when the form is submitted?
on when it has no value. An unchecked box sends nothing, so the server sees no field for it.






















