Radio buttons and checkboxes are used in forms to collect choices from users. Radio buttons allow exactly one selection within a group (all inputs share the same name), while checkboxes let users select any combination of options.
You should always pair these controls with clear labels, group related options using <fieldset> and <legend>, and submit stable value tokens that do not change when the UI text is translated.
<input type="radio"> for single-choice selections.name attribute.required to one radio makes the whole group mandatory.checked for the default selected option.disabled makes an option visible but not selectable.<input type="checkbox"> for multi-select choices.name and value on submit.name="items[]".disabled prevents selection while still showing the option.Basic HTML structure for radio buttons and checkboxes:
<!-- Radio button group (one choice only) -->
<input type="radio" id="contact-email" name="contact" value="email">
<label for="contact-email">Email</label>
<input type="radio" id="contact-phone" name="contact" value="phone">
<label for="contact-phone">Phone</label>
<!-- Checkbox group (any number of choices) -->
<input type="checkbox" id="fruit-apple" name="fruits[]" value="apple">
<label for="fruit-apple">Apple</label>
<input type="checkbox" id="fruit-banana" name="fruits[]" value="banana">
<label for="fruit-banana">Banana</label>
Always group related controls for accessibility:
<fieldset>
<legend>Preferred contact method</legend>
<!-- radio / checkbox controls here -->
</fieldset>
<!-- Radio button group: one choice only -->
<form action="#" onsubmit="return false;">
<fieldset>
<legend>Preferred contact method</legend>
<input type="radio" id="r-email" name="contact" value="email" required checked>
<label for="r-email">Email</label><br>
<input type="radio" id="r-phone" name="contact" value="phone">
<label for="r-phone">Phone</label><br>
<input type="radio" id="r-none" name="contact" value="none" disabled>
<label for="r-none">No contact (disabled)</label>
</fieldset>
<button type="submit">Submit</button>
</form>
<!-- Checkbox group: any number of choices -->
<form action="#" onsubmit="return false;">
<fieldset>
<legend>Favorite fruits</legend>
<input type="checkbox" id="c-apple" name="fruits[]" value="apple" checked>
<label for="c-apple">Apple</label><br>
<input type="checkbox" id="c-banana" name="fruits[]" value="banana">
<label for="c-banana">Banana</label><br>
<input type="checkbox" id="c-cherry" name="fruits[]" value="cherry" disabled>
<label for="c-cherry">Cherry (disabled)</label><br>
</fieldset>
<button type="submit">Submit</button>
</form>
{ }
The buttons above show what data would be submitted: radios send a single contact value, while checkboxes send an array of selected fruits[] values.
<fieldset> with a clear <legend> for accessibility.value (slug/code) such as email or phone instead of the label text.required on any member makes the entire group required.name="items[]" and will parse them into an array.id and link its label with for for larger clickable areas.name; different names mean they can all be selected.required to enforce “at least one” — use custom validation instead.<input type="hidden" name="subscribe" value="no"> followed by <input type="checkbox" name="subscribe" value="yes"> and inspect the submitted values when checked vs unchecked.indeterminate state reflects partial selections (already wired in the live example—read and adapt the JavaScript).type="radio") allow exactly one selected value per name group.type="checkbox") allow multiple selections and often use array-like names such as fruits[].<fieldset> and label everything clearly for accessibility.value tokens and unique id values for reliable behavior.