HTML: input type="radio"
Radio inputs let a user choose one option from a group of mutually exclusive choices.
What you will learn
- How radio buttons form one choice group
- How matching names and distinct values affect submitted data
- When to use radio buttons instead of checkboxes
Minimal example
<fieldset>
<legend>Delivery speed</legend>
<label><input type="radio" name="speed" value="standard" checked> Standard</label>
<label><input type="radio" name="speed" value="express"> Express</label>
</fieldset>Radio inputs with the same name belong to one group. Give each choice a distinct value, and use fieldset and legend when the group needs a shared question.
Common mistakes
- Use checkboxes when users may select several independent options.
- Do not give every radio input a different name if only one choice is allowed.
- Validate the selected value on the server instead of trusting the browser.