radiogroup

Term side of the Card.
Topic: Basic Control Elements
Unit title: radiogroup
Categories: Role
Explanation side of the Card

Explanation: The role used to group together a set of radio buttons where only one option can be selected. It helps users navigate and understand the selection constraints within the group.

Example

Wronghtml
<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>
Righthtml
<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 name values, 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 name and sit in a <fieldset> with a <legend>, or the group has role='radiogroup' and a name.
  • Only one radio in the group is in the Tab order; arrow keys move and select.
  • Custom radios update aria-checked and 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.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy