Switch
Turns a setting on or off, with an immediate effect. When the change waits for a Save button, use a Checkbox.
Installation
Or with the shadcn CLI, from the registry:
Usage
Tones
tone colours the checked track, and the thumb takes the text colour that sits on it: primary by default, or neutral, success, warning, info, destructive. The thumb, at 4.5:1 on the track, is what shows the state.
Sizes
sm, default and lg; the thumb's travel follows the size and the village's border.
Villages
The track and thumb are village tokens (--switch-track, --switch-thumb, --track-border): Iwa borders its track and draws its thumb in ink, without a shadow.
Accessibility
- A
role="switch"button witharia-checked, backed by a hidden input for forms. - Space and Enter toggle it; a linked label toggles it on click.
API reference
The props of Base UI's Switch root (checked, defaultChecked, onCheckedChange, name, required, disabled…), plus:
| Prop | Type | Default |
|---|---|---|
tone | "neutral" | "primary" | "success" | "warning" | "info" | "destructive" | "primary" |
size | "sm" | "default" | "lg" | "default" |
className | string |
switchVariants({ tone, size }) returns the track's classes.