Demos

A switch with its label.

Usage

Use a switch for a setting that takes effect right away, like notifications. If the change only applies after a Save button, use a checkbox instead.

Import it from @workspace/ui/components/switch.

Anatomy

  • Switch — The track and thumb. Wrap it in a label with its text.

Notes

  • The label should describe the setting, not the action. Write "Notifications", not "Turn on notifications".
  • Space toggles the switch when it has focus.

Examples

Sizes

default and sm.

Disabled

A switch that cannot be changed.

Controlled

Hold the state with checked and onCheckedChange.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

Switch

PropTypeDefaultDescription
defaultCheckedbooleanfalseOn by default.
checkedboolean—State when controlled.
onCheckedChange(checked) => void—Called when the state changes.
size"default" or "sm"defaultSize of the switch.
disabledbooleanfalseBlocks input and dims the switch.
namestring—Field name for form submission.