Switch

Turns a setting on or off, effective immediately.

Usage

pnpm dlx shadcn@latest add switch

Then 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

Off
On

States

Focus, disabled and invalid
Focus
Disabled · on
Disabled · off
Invalid

Sizes

sm · md
sm · 28×16
md · 36×20 (default)

With a label

Settings rows
Switch before the label

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…UseWhy not the other
A setting that takes effect the moment it changesSwitchNo Save button; the system changes as you flip it.
A form value saved when the form is submittedCheckboxA switch promises an immediate change the form can't deliver.
Agreeing to something ("I accept the terms")CheckboxConsent is a value you submit, not a setting you flip.
Two or more options where only one can be onRadio groupTwo switches that can't both be on are a radio group in disguise.
Filtering a listCheckboxFilters change the view, not the system.
Turning on a whole feature that reveals more settingsSwitchOn 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.