HTML Checkboxes and Radio Buttons: Select Choices
Independent checkboxes
A checkbox lets a user turn a choice on or off. Several checkboxes may share a name and each checked control contributes its own value. The checked attribute establishes the starting state.
<form> <label> <input type="checkbox" name="topic" value="html" checked> HTML </label> <label> <input type="checkbox" name="topic" value="css"> CSS </label></form>Initially only topic=html is included. Select CSS to add its value.
One choice from a radio group
Radio inputs with the same non-empty name, same form owner and same tree form an exclusive group. Selecting one clears another selected member. Different names create different groups.
<form> <p>Delivery method</p> <label> <input type="radio" name="delivery" value="pickup" checked> Pickup </label> <label> <input type="radio" name="delivery" value="mail"> Mail </label></form>Select Mail to switch the single submitted delivery value.
Unselected is omitted
When no checkbox is checked, its key is absent. A checked checkbox without an explicit value uses on. Use explicit values so a server can tell what the user selected.
<form> <label> <input type="checkbox" name="alerts" value="yes"> Alerts </label> <label> <input type="checkbox" name="updates" checked> Updates </label></form>Initial form data includes updates=on, but not alerts.
Common mistakes and practice
checked is Boolean: checked="false" still means initially checked because the attribute exists. Unchecked choices are omitted, not sent as false. Always supply useful values instead of relying on the default on. Radio options within the same form and tree share a name; give each a distinct id if using explicit labels.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Checkboxes and Radio Buttons: Select Choices — Knowledge Check
Apply the form-control concepts from this lesson.
How do two radio inputs in the same form and tree become one group?
What is submitted for an unchecked checkbox?
What does checked="false" mean in HTML?
Two independent preferences may both be selected. Which control type fits?
A checked checkbox has name="updates" and value="yes". Which entry does it contribute?