radiogroup
Example
<p>Shipping</p>
<input type="radio" name="fast" id="f"> <label for="f">Fast</label>
<input type="radio" name="slow" id="s"> <label for="s">Slow</label><fieldset>
<legend>Shipping</legend>
<label><input type="radio" name="ship" value="fast"> Fast</label>
<label><input type="radio" name="ship" value="slow"> Slow</label>
</fieldset>A shared name makes one group with arrow key navigation, and the legend gives the group its accessible name.
Common mistakes
- Radio inputs with different
namevalues, so the browser treats them as separate groups. - A group question shown as plain text that is not tied to the radios.
Key points
- Native radios share one
nameand sit in a<fieldset>with a<legend>, or the group hasrole='radiogroup'and a name. - Only one radio in the group is in the Tab order; arrow keys move and select.
- Custom radios update
aria-checkedand only one is 'true' at a time.
Interview questions
Fieldset or role='radiogroup': which should I use?
Use <fieldset> with <legend> for native radios. Use role='radiogroup' with aria-labelledby for custom role='radio' elements.
How should arrow keys work in a radio group?
Arrow keys move to the next or previous radio and select it. Tab leaves the group.