Skip to content

Toggle Group

The group is radio buttons in disguise. Each option is a <label> with an <input type="radio"> inside, shrunk away visually. You keep the arrow keys, FormData and the screen reader saying “2 of 3”, without having to rewrite any of it.

<legend> is required even when it is hidden. Without it, someone listening to the page does not know what the three options choose between.

SituationComponent
One choice among three to five short optionsToggle Group
One choice among many, or long optionsRadio in a Fieldset
Several choices at onceCheckbox
On and off for one settingSwitch
Actions, such as “bold, italic, underline”Buttons with aria-pressed
ClassWhat it is
.lt-toggle-groupThe group
.lt-toggle-group__optionThe label around each option
VariableDefault
--lt-toggle-group-radiusvar(--lt-spacing-1)
--lt-toggle-group-heightvar(--lt-spacing-10)
--lt-toggle-group-padding0 var(--lt-spacing-4)

The selected surface is set with :has(input:checked), that is from the state of the real radio button. There is no separate class to keep in sync.

See Customising for how the variables and the layer work.

  • The radio button is shrunk away, not removed. display: none would take it out of the keyboard order, and the arrow keys would then stop working.
  • The arrow keys move between the options and select at the same time. Tab leaves the whole group. That is how radio buttons work, and it should not be overridden.
  • The options have to be short. If the text gets long, it is really a list of radio buttons.
  • Do not let a choice trigger something that cannot be undone. The user lands on every option on the way when moving with the arrow keys.