CKTIS / HTML
checked: default and current selection
Understand checkbox and radio defaults, user changes and form reset.
Version: HTML Living Standard
Syntax
<input type="checkbox" name="topic" value="html" checked>The boolean attribute checked gives a checkbox or radio input its default checked state. Presence matters, so checked="false" still supplies a checked default. Radio buttons in the same group allow only one current selection; a checkbox is independently selectable. This attribute is not the default-value mechanism for ordinary text fields.
After interaction, distinguish the current checked DOM property from defaultChecked, which reflects the default attribute. Changing the attribute is not a reliable substitute for changing current state after the control has become dirty. Resetting the form restores the defaults. An unchecked checkbox is omitted from ordinary form data, rather than submitted as the boolean false.
The example starts checked, activates the control to uncheck it, inspects the submitted field set and resets the form. The output demonstrates both omission while unchecked and restoration to the checked default. A mixed visual checkbox state is a separate script-controlled property and should not be mistaken for a third attribute value.
Examples
<!doctype html><meta charset="utf-8">
<form id="form"><label><input id="topic" type="checkbox" name="topic" value="html" checked> HTML</label></form>
<output id="result"></output><script>
const field = document.querySelector('#topic'), form = document.querySelector('#form');
const initial = field.checked;
field.click();
const afterClick = field.checked, submitted = new FormData(form).has('topic');
form.reset();
document.querySelector('#result').textContent = 'initial=' + initial + '; afterClick=' + afterClick + '; submitted=' + submitted + '; afterReset=' + field.checked + '; default=' + field.defaultChecked;
</script>Result
initial=true; afterClick=false; submitted=false; afterReset=true; default=true
The form-data check concerns presence of the named field, not whether its textual value equals true.