Radio
BetaFormsOpen in the workshop
One choice out of two to six, all visible at once.
.xg-check > input[type=radio] inside .xg-fieldsetExample and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<fieldset class="xg-fieldset">
<legend class="xg-label">Pacing</legend>
<label class="xg-check">
<input type="radio" name="pace" checked>
<span>Even<span class="xg-check__hint">Spread the budget across the day</span>
</span>
</label>
<label class="xg-check">
<input type="radio" name="pace">
<span>As fast as possible<span class="xg-check__hint">Spend as soon as traffic allows</span>
</span>
</label>
<label class="xg-check">
<input type="radio" name="pace" disabled>Front-loaded (soon)</label>
</fieldset>States
Hover, focus and pressed are forced here with .is-hover, .is-focus and .is-active so they can be seen side by side; in a product they come from :hover, :focus-visible and :active.
| State | Radio |
|---|---|
| Unselected | |
| Selected | |
| Disabled | |
| Disabled selected |
When to use it
Use it for
mutually exclusive options that need a sentence each (billing model, pacing).
Not for
more than six options (Select); short labels in a toolbar (Segmented control).
Rules
- Always one option selected by default when a safe default exists.
- Options read as a list, vertically.
Accessibility
- Same name on every radio; <fieldset> and <legend> name the group. Arrow keys move the selection natively.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Forms: Input, Textarea, Select, Checkbox, Switch, Segmented control, Search field, Date-range picker, Form layout.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).