Switch
Turns one setting on or off, right away. Off, the thumb is small and quiet; on, it grows and slides across a filled track. Press and hold to feel it swell.
Install
npx shadcn@latest add @nelumbo/switchStates
Black when on, white in dark mode. Hover shows a soft halo around the thumb.
off
on
disabled
disabled on
Icons
A check and a cross inside the thumb make the state readable without color. The thumb stays full size in both states.
off
on
Brand color
For a switch that should carry the accent, for example a feature you are promoting.
Sizes
Default (52 × 32) and sm (40 × 24), for dense lists and table rows.
default
sm
sm, icons
In a settings list
Wrap the row in a label, so clicking anywhere on it flips the switch. The title names the switch, and the description is read with it.
Usage
import { Switch } from "@/components/ui/switch"<label className="flex items-center justify-between gap-4"> Wi-Fi <Switch checked={wifi} onCheckedChange={setWifi} /></label><Switch icons color="brand" aria-label="Beta features" />Props
Other props go to Radix Switch (checked, defaultChecked, onCheckedChange, name, required…).
| Prop | Type | Default | Notes |
|---|---|---|---|
icons | boolean | false | Check and cross inside the thumb |
color | "auto" | "neutral" | "brand" | "auto" | |
size | "default" | "sm" | "default" | 52 × 32 or 40 × 24 |