Use Radio Button...
- To prompt users to choose from a set of mutually-exclusive choices.
- Inside a Selection Set as
variant="single-select"
.
Don't use Radio Button...
- To select more than one option. Use Checkbox instead.
- To prompt users to choose between two mutually exclusive options that always has a default value, like “On” or “Off”. Use Toggle Switch instead.
Accessibility
Radio Button wrapping
Use RadioButton
within a Selection Set.
Alternatively, if you wish to have more control over your layout, either:
- Use Fieldset to place the radio buttons inside.
- Or use an element that has both
role="radiogroup"
and the mandatoryaria-labelledby
attribute. The value ofaria-labelledby
should be theid
of the element serving as the title for the radio group. If the group lacks a visible title, use thearia-label
attribute with a descriptive title for the radio group. Ensure the value ofaria-label
is localized, since some browsers read it aloud to the user.
Required field
When a radio button is required for form submission:
- Use
aria-required="true"
on the Radio Buttons' wrapper (it tells AT that this form input is required). - Also, use
required
on all of the Radio Buttons in the wrapped group (it tells the browser to block form submission until one of them is selected).