Browse the docs

Switch

The knob is a little face. It sleeps when off and wakes up when you flip it on.

Client componentWCAG AASince v0.1

Live example

Change every prop live in the playground.

Props

PropTypeDefaultWhat it does
aria-labelstringnoneAccessible name when there is no visible label.
checkedbooleanfalseControlled state.
childrenReactNodenoneThe label. Clicking it toggles the switch.
classNamestringnoneExtra class on the label row that wraps the switch.
color"ink" | "tomato" | "mint"mintTrack color when on.
defaultCheckedbooleanfalseUncontrolled initial state.
disabledbooleanfalseGreys out the switch and its label and blocks toggling.
idstringnoneId of the switch button, for an external <label htmlFor>.
namestringnoneField name submitted with a form.
onCheckedChange(checked: boolean) => voidnoneCalled with the new state when the switch is toggled.
requiredbooleanfalseMust be on before the form can submit.
valuestringonValue submitted with a form when on.

Use it well

DoUse it for settings that take effect right away.
Don'tUse it inside a form that needs a Save button. That's a Checkbox.

Accessibility

  • Built on the Radix Switch: role="switch" with aria-checked.
  • Clicking the label toggles it; Space and Enter work from the keyboard.
  • On and off also show in the knob's position and face, not only color.
Five stamps!

All aboard.

You took the whole tour. Here's Holo Pip, a foil sticker for riders who finish. It's in your playground tray now, for good.