Radio
A single choice within a set. The options share a name and sit inside a role="radiogroup". Supports a description per option (has-description) and, on the group, a label, error, and hint.
Forms · TaishoDS Core, in plain HTML.
Examples
One working example per case. Each example is the HTML of its preview—copy it as is, and with Core’s CSS and JS loaded, it looks and works the same.
Plan group
Environments with descriptions
Options as cards
Required with error
Class reference
Every value of each modifier, with its HTML ready to copy.
Size
Control size: sm, md, or lg.
Variant
The color when selected. primary by default, which takes the theme primary (primary; the brand if you don’t set one), or a status color.
Density
The spacing around the control and its label.
Combinations
Size and color combined.
When to use
- Choosing exactly one of a few options that are best seen all at once.
- The options need a description or more context (
has-description). - You want comparing the options to be visible without opening anything.
When not to use
- It’s 2–4 options to switch a view or filter →
segmented-control. - There are too many options to fit comfortably →
select. - More than one can be chosen →
checkbox.
Do
- Always put the options inside a
role="radiogroup"and leave one checked by default. - Give the group a name (
aria-label). It names the question (“Environment”). Inside thefieldmarkup, thefieldprovides the name. - Show the error once on the group, not on each option.
- Order the options logically (by frequency or magnitude).
Don’t
- Don’t use it for a single yes/no option →
checkbox. - Don’t use it for long lists. It turns into a wall of options →
select.
Related
TaishoDS Core
Needs Core’s JS, which hooks in through data-ts-* attributes.
It’s a native <input type="radio">, grouped by name. To paint the state, Core mirrors checked to the label’s is-checked class (and clears it from the rest of the group). The label, error, hint, and description are markup the example already includes.
What it does: When the selection changes, it mirrors checked to the label’s is-checked class and clears it from the other radios with the same name in the same form (or the same container when there is no form). Keyboard, focus, and submission are the browser’s.
From the CDN, without a build, load taisho.radio.css along with taisho.base.css. Also load:
taisho.icon.css
For how Core works in general, see Behavior.
Accessibility
Implements the Radio Group pattern from the WAI-ARIA APG.
- It’s built on a native
<input type="radio">with a sharedname. The arrow keys move the selection within the group. - If a choice is required, each
<input type="radio">carriesrequired, and therole="radiogroup"container setsaria-required="true". - The group is named with
aria-labelledbypointing to the visible text. The hint text and the error message describe it witharia-describedby, and the error addsaria-invalid="true"(announced witharia-live="polite").
Keyboard
On top of what the browser already does (Tab moves focus, Enter activates a button).
| Key | What it does |
|---|---|
| ↑↓←→ | Moves the selection between the group’s options. |
Verification
What was actually tested. Anything that wasn’t tested says so—we’d rather say “not verified” than claim too much.
- axe WCAG 2.2 A + AA in a real browser, in light and dark mode, before every release.
- keyboard Key map documented above, checked against the component.
- screen reader Not verified with a screen reader. Test it in your own combination of components, not just here, where each one appears alone and on its happy path.