Design System

Design System

Radio

Forms

Open in Storybook: Radio (opens in a new tab)

On this page

Overview

A short list of choices where exactly one is chosen: a size, a colour, how often, yes or no. It is a fieldset with a legend and, for each choice, an input type="radio" and its label, side by side and tied by for and id. The browser gives the group, the role, the state, one Tab stop, the arrow keys that move and choose, and the value in a form. The component adds paint and nothing else.

The rule. One name for every radio. Never an input inside its label. No role="radio", no role="radiogroup", no aria-checked, no tabindex, no ul, and no script for the keys. The legend is the question and the label is the choice. Choosing changes no context: it never navigates, submits or opens.

Live example

How often should we deliver?

Anatomy

  1. Group

    fieldset

    The group. It is named by its legend and described by its hint.

  2. Legend

    legend

    First child. The question the radios answer: the name of the group.

  3. Hint

    p

    Optional. One line for the whole group, read after its name with aria-describedby on the fieldset.

  4. Control

    input type="radio"

    The browser’s own element, painted. One name for the group, and the value is what a form sends.

  5. Label

    label

    Next to the control, never around it, with for set to its id. Its words are the name of the radio, and the whole row is the click target.

  6. Description

    p

    Optional. A line more for one choice, read after its name with aria-describedby on the input.

Usage

Use cases

Seven recipes, each the real component and each working. They are the same parts: only the words, the paint and the layout change.

  • A short choice

    Three words to pick one from, with a hint

    How often should we deliver?

    You can change it at any time.

    fieldset · legend · one name · input type="radio" and its label

    The group is named by the legend and described by the hint. One Tab stop, and the arrow keys move and choose.

  • A choice with a line more

    A price and a date after the name

    Delivery

    Free. Arrives in 3 to 5 days.

    €6.00. Arrives tomorrow.

    Free. Ready in 2 hours.

    aria-describedby on the input · the line under its label

    The label is the name and the line is the description, so the price is not part of the name.

  • Size

    One short word each, side by side, and one that is gone

    Size

    legend · disabled on the one that is sold out

    The sold out size stays in sight with its reason in its name, and the arrow keys skip it.

  • Colour

    The control is the colour, and its name is beside it

    Colour

    --rd-swatch · the name is the colour · a ring outside when on

    The colour stays whole when it is chosen. It is never the only cue: the name says it, and the ring says it is chosen.

  • Colour only

    Just the colours, with the labels visually hidden

    Colour

    swatchOnly · the label is visually hidden · the colour is the target

    A screen reader hears “Sage” and the ring shows which is chosen. A person who talks to the page cannot say a name they cannot see.

  • Yes or no

    Two answers that are both a choice, and none to begin with

    Do you have a promo code? (required)

    required on each · “(required)” in the legend

    Nothing is chosen until the person does it. One answer on its own is a checkbox.

  • Only accent-color

    The browser’s own radio, tinted

    How often should we deliver?

    accent-color: var(--lilac) · no appearance: none

    The least CSS: the browser draws the control and its focus, and only the tint is ours.

Props

Props
PropDoesDefault
legendNames the group: the question the radios answerRequired
nameThe one name of every radio, which is what makes them a groupRequired
optionsThe choices: value, label, and optionally description, swatch (a colour: the control is painted in it) and disabledRequired
hintOne line for the whole group, read after its name. Also on the page
defaultValueThe value that is chosen to begin with. Without it, none is
value, onValueChangeFor a page that owns the state: the value that is chosen, and a call for each choice
requiredEvery radio is required, and the legend says “(required)”false
inlineSide by side, wrapping, for choices that are one short wordfalse
nativeThe browser’s own drawing, tinted with accent-color. A swatch has no place in itfalse
swatchOnlyOnly the colours are drawn, for the options that have a swatch: the label of each is visually hidden, side by sidefalse

Specs

Markup

<fieldset aria-describedby="frequency-hint">
  <legend>How often should we deliver?</legend>
  <p id="frequency-hint">You can change it at any time.</p>
  <input type="radio" id="week" name="frequency" value="week">
  <label for="week">Every week</label>
  <input type="radio" id="fortnight" name="frequency" value="fortnight" checked>
  <label for="fortnight">Every two weeks</label>
</fieldset>

<!-- a choice with a line more: the line is the description of the input -->
<input type="radio" id="express" name="delivery" value="express"
       aria-describedby="express-line">
<label for="express">Express</label>
<p id="express-line">€6.00. Arrives tomorrow.</p>

Native tags

Native tags
TagAttributeWhat it gives
fieldsetnoneThe group: the role group, named by its legend. Its own edge and padding are cleared
legendfirst child of the fieldsetThe name of the group: the question
inputtype="radio"The control: the role radio, a checked state, the arrow keys, one Tab stop for the group
inputnameThe same on every radio. It is what makes them a group, and the key of the value in a form
inputidWhat the label points at with for
inputvalueWhat the form sends for the one that is chosen
inputcheckedThe choice made to begin with. At most one radio of a group has it
inputrequiredThe form is not valid until one is chosen. It is on every radio of the group, and the legend says so in words
inputdisabledOut of the arrow keys, out of the Tab order and out of the form. It stays in sight
labelfor, next to the inputThe name of the radio, and the click target of the row. It is never around the input
fieldsetaria-describedbyThe hint, read after the name of the group
inputaria-describedbyOnly when a choice has a line more: it points at the line under the label

Native CSS properties

Native CSS properties
PropertyOnWhat it does here
appearance: nonethe controlTakes the browser’s drawing off, so the control is painted with CSS. It is still the browser’s own element
accent-colorthe control, nativeTints the browser’s own radio and its focus: the least CSS
inline-size, block-sizethe control1.5rem, which is 24px. A swatch is 2rem
box-sizing: border-boxthe controlThe border does not make it bigger: the 7px ring of on is inside the same 24px
borderthe control2px ink when off, 0.4375rem (7px) lilac when on: the ring is thicker, not another colour
border-radius: 50%the controlA circle
background-colorthe controlwhite, wash under a pointer, and the colour of a swatch
outline, outline-offsetan on swatchA 3px ink ring 2px outside the colour, so the colour is not made smaller by being chosen. The site’s focus halo is a box-shadow, so both show
position: absolute, clip-path: inset(50%)the label, swatchOnlyA box of 1px that is not seen. It is still the name of the radio in the tree
:checked, :disabled, :focus-visiblethe controlThe states, drawn from the browser’s own state: no class is added and no script runs
:disabled + labelthe labelMutes the words of a choice that is unavailable
@media (hover: hover), :has(+ label:hover)the controlThe hover fill exists only where there is a pointer, and follows the label under it
@media (forced-colors: active)the controlThe ring is Highlight. A swatch has forced-color-adjust: none, so it keeps its colour
display: grid, grid-template-columns: auto 1frthe groupThe control in the first column, its label and the line under it in the second: they are side by side in the DOM, so the grid puts each pair on a row
min-block-size: 2.75remthe labelA row is 44px at least: the label is the click target
cursorthe labelpointer, and not-allowed for a choice that is unavailable
grid-template-columns: repeat(n, auto auto)the group, inlineA pair after a pair on one row. Under 40em, in text size and not in pixels, one on each row
display: flex, flex-wrap: wrapthe group, swatchOnlyThe colours on a row that wraps

Styling

.rd__input {
  box-sizing: border-box;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  margin: 0;
  cursor: pointer;
}

.rd__input--painted {
  appearance: none;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background-color: var(--white);
}

.rd__input--painted:checked {
  border: 0.4375rem solid var(--lilac);
}

.rd__input--native {
  accent-color: var(--lilac);
}

.rd {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
}

.rd__label {
  display: flex;
  align-items: center;
  min-block-size: 2.75rem;
  padding-inline-start: 0.75rem;
  cursor: pointer;
}

States

States
StateLookExposed
Off2px ink edge, white fill, 24pxnot :checked
Hoverwash fill, only under a pointerthe same
On7px lilac ring around a white centre:checked
Focusthe site’s ring: its halo around the control:focus-visible. The edge keeps its colour
Disableddashed ink-soft edge, ink-soft words, not-allowed cursordisabled
On, a swatchthe colour whole inside its 2px edge, and a 3px ink ring outside it:checked
On, forced colorsHighlight ring, 7pxthe same

Measurements

Measurements
PartPropertyValue
Controlinline-size, block-size24px, and 32px for a swatch
Control, offborder-width2px
Control, onborder-width7px, which leaves a centre of 10px
Swatch, onoutline-width, outline-offset3px and 2px, outside the 32px of colour, which is the same as off
Swatch onlythe colour32px by 32px, which is the target: the label is hidden
Labelmin-block-size44px, which is the row. 32px when a line is under it
Labelpadding-inline-start12px, between the control and the words, and part of the click target
Legendfont-size, font-weight16px, 700
Labelfont-size, font-weight16px, 400. With a line under it the label is 700, and the line is 15px, 400

Where it differs from the Figma

Where it differs from the Figma
ThingThe Figma page “Radio groups”The component
FocusA 3px ring in #1B4FD1, 2px away from the control, on the cardThe site’s ring, on the control itself: a simple radio has no card
Thickness when onThe Look table says 0.45rem; the drawing is 7px7px (0.4375rem), as drawn
Forced colorsA black fill and a ring in #1A80FFThe ring is Highlight, the system’s own
HoverNone for the control: the card has a darker borderA wash fill, only under a pointer
Colour nameThe Swatch row of the use cases says “Visible colour name”. Section 7b, Colour only, has the label visually hiddenBoth: seen by default, and hidden with swatchOnly
Swatch, onSection 7b: the colour whole, with a 3px ink ring 2px outside itThe same
Swatch, focusSection 7b: the page’s 3px ring, 2px outside the ring of the choiceThe site’s halo, under the ring of the choice: both show
Disabled, native, inlineNot drawn, except a disabled colour in section 7bAdded: a sold out size, the least CSS and a row of short words need them

Tokens

Component tokens

Component tokens
PartPropertyTokenValue
Control, offborder-colorink#16161a
Control, offbackground-colorwhite#ffffff
Control, off, hoverbackground-colorwash#edebf4
Control, onborder-colorlilac#5e548e
Control, disabledborder-color, wordsink-soft#4b4b55
Swatchborder-color, outline-color when onink#16161a
Wordscolorink#16161a
Hint, line under a choicecolorink-soft#4b4b55
Nativeaccent-colorlilac#5e548e
Focusbox-shadowfocus-ring-soft, focus-ring-primary#a5c8ff, #0066ff

Guidelines

Radio or something else?

Radio or something else?
NeedUse
Exactly one of a short list, two to about sixRadios
More than one can be chosenCheckboxes in a fieldset
One yes or no on its ownA checkbox, or a switch when it acts at once
A long list, about seven or moreA select
Choosing acts at once: navigate, filter, applyButtons, links or tabs
Each choice has an image, a price or controls of its ownA radio card, which is its own build: read the post

Content

Content
PartFormatExample
LegendThe question or the noun: no colon, and no “Choose”“How often should we deliver?”, “Size”
LabelThe choice, in few words, never repeating the legend“Every two weeks”, “M”
HintOne line for the whole group“You can change it at any time.”
Line under a choiceOne line more for that choice: a price, a date“€6.00. Arrives tomorrow.”
UnavailableThe reason in the label, so it is read with the name“XL, sold out”
Colour without wordsThe label visually hidden, with the same words as when it is seen“Sage”
First choiceMade for the person when one is a fair default. None when both answers are a choice“Every two weeks”; yes or no has none

Hidden names

Hide the names with swatchOnly only where the colour is the choice, as a row of colours for a product. The name is still the name of the radio for a screen reader, and the ring shows which is chosen. A person who talks to the page cannot say a name they cannot see, so show the names where that matters. Anything that is not a colour keeps its words.

Behavior

Behavior
EventResult
Choose, with a pointer or Spacethe others turn off and the page is told once. Nothing else happens: no navigation, no submit, no dialog (3.2.2)
Tabenters the group once, on the chosen radio, or on the first when none is. The next Tab leaves it
Arrow keysmove focus and choose in one step, and wrap at the ends
Space on the radio that is chosennothing, and the page is not told
A radio that is disabledis skipped by the arrow keys and by Tab, and is not in the form
required with none chosenthe form is not valid. The message is the form’s: this component shows none

Accessibility

Keyboard

Keyboard
KeyActionNative
Tab, Shift+Tabone stop for the whole group: the chosen radio, or the first when none isyes
ArrowDown, ArrowRightthe next radio, which is chosen. After the last, the firstyes
ArrowUp, ArrowLeftthe radio before, which is chosen. Before the first, the lastyes
Spacechooses the radio that has focus, when it is not chosenyes

Roles and properties

Roles and properties
PropertyExposedNote
role of the groupgroupnamed by the legend
role of a choiceradioimplicit
namethe text of the labelthe words of the choice, when it has a line more. Not the line, and not the paint
descriptionthe hint, for the group, and the line, for a choicearia-describedby
checkedtrue or falsefrom the browser: there is no aria-checked
disabledtruea choice that is unavailable
requiredon each radiothe legend says it in words as well

Measured behavior

Chromium 148.0.7778.96, from the tests. Nothing here was heard in a screen reader yet.

Measured behavior
ObservationConsequence
The browser’s tree has a group named by the legend, and a radio for each choice with its name, its description and checkedno ARIA is needed for any of it
With aria-describedby, the name is “Standard”, from its label, and the description is the linethe price is not part of the name
A sold out radio is in the tree, disabled, with its reason in its nameit is found and understood, not hidden
Tab lands on the chosen radio, or on the first when none is chosenone stop for the group, as native radios do
The arrow keys wrap, and skip a radio that is disabledno script is needed, and none is wanted
Space on a radio that is already chosen fires no changethe page is told once for each choice
The site’s rule for an input sets border-color on focusthe component sets its own on :focus-visible, so on is still the ring of the lilac
The colour of a swatch is not in the namethe name is the colour: “Sage”, not a dot
With swatchOnly the name is the label that is visually hidden: “Sage”, “Indigo”a screen reader gets the same words as when they are seen
A colour that is chosen keeps its 32px and its 2px edge, and the ring is an outline outside itthe colour is whole, and the focus halo and the ring are both there

Support

Support
BrowserChecked
Chromium 148yes, in the tests
WebKit, Firefoxnot run

WCAG criteria

WCAG criteria
CriterionLevelRequirement here
1.3.1 Info and Relationships (opens in a new tab)Afieldset and legend make the group, the label names each radio, aria-describedby carries the hint and the line
1.4.1 Use of Color (opens in a new tab)Aon is a thicker ring, not another colour, and the colour of a swatch is also its name
1.4.6 Contrast (Enhanced) (opens in a new tab)AAAthe words are 18.0 to 1, and the hint and the line are 8.6 to 1, over white
1.4.10 Reflow (opens in a new tab)AAno sideways scroll at 320px with the text at 200%: the words wrap
1.4.11 Non-text Contrast (opens in a new tab)AAthe edge is 18.0 to 1 and the ring of on is 6.7 to 1 against the page. A colour has an edge of 18.0 to 1 and a ring of 18.0 to 1, so a pale colour is found
2.1.1 Keyboard (opens in a new tab)Anative radios: Tab, the arrow keys and Space
2.4.7 Focus Visible (opens in a new tab)AAthe site’s ring is shown by :focus-visible
2.5.3 Label in Name (opens in a new tab)Athe name is the visible label. With swatchOnly there is none to differ from
2.5.8 Target Size (Minimum) (opens in a new tab)AAthe row is 44px high and the control is 24px
3.2.2 On Input (opens in a new tab)Achoosing changes no context
3.3.2 Labels or Instructions (opens in a new tab)Athe legend, “(required)” and the hint are words on the page
4.1.2 Name, Role, Value (opens in a new tab)Aa native radio, with its name and its checked state

Related

This section is still in progress.

References

W3C standards

HTML Standard (WHATWG)

W3C WAI

MDN Web Docs