Skip to content

Radio

Plain CSS on an ordinary <input type="radio">. The buttons in a group are tied together by name, and that is what lets only one be selected, and lets the arrow keys move between them.

If the user can choose several, use Checkbox. If there are many options, Select takes less room on the screen.

The group always belongs in a Fieldset. Without it only the option is read out, not the question it answers.

data-stateUsed for
(omitted)Normal state
invalidValidation has failed
successThe choice is confirmed valid. Use sparingly.

If validation fails, set the state on every button in the group. It is the group that is invalid, not one of the buttons.

ClassWhat it is
.lt-radioThe button itself
.lt-radio-rowThe row that holds the button and the text side by side
VariableDefault
--lt-radio-sizevar(--lt-spacing-5)

The dot is a gradient drawn in --lt-color-accent-content, so it follows the theme without a separate image. See Customising.

  • Every button in the group has to share name. Without it each button becomes its own group, and the user can choose several.
  • The arrow keys move between the buttons and select at the same time. Tab leaves the whole group. That is the browser’s own behaviour, and it should not be overridden.
  • Do not preselect an option when the choice has a consequence. The default then becomes an answer the user never considered.
  • If you only have two options that are each other’s opposite, consider Checkbox or Switch instead.