Components · Form

Radio button

A radio button lets the user choose exactly one of two or more mutually exclusive options. Choosing one clears the others in the group.

How to add a radio button to a page. The file is components/css/radio.css.

Basic Usage

Link the shared stylesheet once per page. Never copy the rules into a page, and never draw the circle with an image.

StepWhat to do
1. Link<link rel="stylesheet" href="/components/css/radio.css">. Both templates already have it.
2. MarkupA fieldset.form-radio-group with a legend. Each option is a label.form-radio-item around an input[type="radio"] and a span.
3. GroupGive every radio in the group the same name, and preselect one with checked.
4. SizeLarge is the default. Add form-radio-item--sm for Small.

Radio button

Copy the markup you need. Hover and focus come from :hover and :focus-visible; the [data-state] selectors in the CSS exist only so the documentation can force a state.


API

Classes

ClassUse
form-radio-groupThe fieldset. Vertical by default.
form-radio-itemThe option label. Large.
form-radio-item--smSmall size.
form-radio-fieldWraps an option and its message.
form-radio-messageThe hint under the label.

Things to know

  • The circle is the native input with appearance: none. The dot is a radial gradient, so no image file is loaded.
  • Arrow-key navigation needs the same name on every radio of a group.
  • For a horizontal group set flex-direction: row on the fieldset (two short options only).
  • Breakpoint: the Large label is 16/22 below 769px and 17/24 from 769px. The CSS does this by itself.
  • The [data-state] selectors do nothing outside the documentation pages.

CSS / Tailwind

The component is one CSS file, shared by every page. Link it, never copy it. The CSS below is read from the file the page links, so it is always what you see.

CSS (components/css/radio.css)