Switch
Turns a setting on or off, effective immediately.
Usage
pnpm dlx shadcn@latest add switchThen replace components/ui/switch.tsx with the Matrix version. It keeps shadcn's API (checked, onCheckedChange, defaultChecked) and adds the Matrix sizes and look. shadcn's size="default" still works (same as md).
import { Switch } from '@/components/ui/switch';
import { Field, FieldLabel } from '@/components/ui/field';
<Field orientation="horizontal">
<FieldLabel htmlFor="auto-run">Run agents on a schedule</FieldLabel>
<Switch id="auto-run" checked={enabled} onCheckedChange={setEnabled} />
</Field>Variants
States
Sizes
With a label
Agents start their tasks at the times you set.
Play a sound when a task finishes.
On every device you're signed in on.
The switch can sit at either end. In settings lists, put the label first and the switch at the end of the row, so switches line up down the page. In short lists or inside a form, it can lead like a checkbox. Keep one side per screen.
Switch or checkbox?
| The control is for… | Use | Why not the other |
|---|---|---|
| A setting that takes effect the moment it changes | Switch | No Save button; the system changes as you flip it. |
| A form value saved when the form is submitted | Checkbox | A switch promises an immediate change the form can't deliver. |
| Agreeing to something ("I accept the terms") | Checkbox | Consent is a value you submit, not a setting you flip. |
| Two or more options where only one can be on | Radio group | Two switches that can't both be on are a radio group in disguise. |
| Filtering a list | Checkbox | Filters change the view, not the system. |
| Turning on a whole feature that reveals more settings | Switch | On its own row, above the settings it reveals. |
Behavior
It applies immediately
A switch has no Save. If a change needs confirming or can be abandoned, it's a checkbox in a form.
Space toggles
The same as Checkbox and Radio. Screen readers announce it as on or off, not checked.
The slide carries meaning
The thumb's movement is how people read the change, so it animates even where other motion is reduced.
API reference
Prop
Type
Guidelines
- Use a switch only for settings that apply immediately.
- Label what turns on, not the state: "Sounds", not "Sounds on/off".
- If the change takes a moment, show progress next to the switch instead of disabling it silently.
- Don't put a switch in a form with a Save button; use a checkbox.