Live example

Sent two days before departure
Usage
<Switch label="Reduce motion" checked={reduced} onChange={setReduced} />

Props

Switch props
PropTypeDefaultDescription
labelReactNodenoneVisible label, referenced by aria-labelledby.
checked?booleannoneControlled state.
defaultChecked?booleanfalseUncontrolled initial state.
onChange?(checked: boolean) => voidnoneCalled with the new state.
description?ReactNodenoneHelp text.
labelPosition?'start' | 'end''end'Label before or after the track.

Do and don't

Do

  • Use for preferences that apply right away, like theme or motion.
  • Label the setting, not the state: "Reduce motion", not "On".

Don't

  • Use inside a form that needs a submit; use Checkbox.

Accessibility

  • A button with role switch and aria-checked, labelled by the visible text.
  • The thumb moves and the track fills, so state is not shown by color alone.

Keyboard

Switch keyboard support
KeysAction
Space, EnterToggles the switch