Forms
Switch
A setting that takes effect immediately, with no save step. If the change only applies when a form is submitted, use a checkbox instead.
Purpose
The distinction from Checkbox is when the change lands. A switch applies at once; a checkbox is collected and submitted with the rest of the form.
Example
States
On, off, and both disabled. A disabled switch keeps its position so the current setting stays readable.
Structure
| Property | Value |
|---|---|
| Track | 24 × 44px (h-6 w-11), fully rounded |
| Thumb | 20px (size-5), white, --shadow-1, travels 20px |
| On fill | --primary · off fill --border |
| Focus | 2px --ring, offset 2px |
| Disabled | 50% opacity, not-allowed cursor |
Best practices
Do
- Reserve switches for settings that apply the moment they are flipped.
- Label the switch with what it turns on — "Paperless statements", not "Enable/disable".
- Put the label after the switch and link it with
htmlFor, so clicking it toggles too.
Don't
- Use a switch inside a form that ends in a Save button — that is a Checkbox.
- Word labels as questions or negatives ("Don't notify me") — flipping one becomes a puzzle.
- Rely on colour alone to signal state — the thumb position must carry it, and it does.
Accessibility & keyboard
- Renders a real button with
role="switch"; screen readers announce the on/off state fromaria-checked. - Label the switch with what it turns on, not the current state, and pair it via
htmlFor— clicking the label toggles the switch. - Focus shows a 2px
--ringoutline with offset — never remove it. - Keyboard: Space or Enter toggles; Tab moves focus.
Props
Switch is a styled re-export of the Radix Switch root — it takes checked / onCheckedChange
for controlled use, defaultChecked for uncontrolled, plus disabled, required, name and
value for forms. See the Storybook prop
tables for the full generated API.