Switch
Toggle switch in two sizes.
Install
npx shadcn@latest add https://plinth.dhrumilkherde.com/r/switch.jsonUsage
import { Switch } from "@/components/ui/switch";
<Switch checked={enabled} onCheckedChange={setEnabled} />Use a switch for settings that apply immediately; use a Checkbox inside forms that submit.
Props
| Prop | Type | Default |
|---|---|---|
size | sm · md | md |
checked / defaultChecked | boolean | — |
onCheckedChange | (checked, details) => void | — |
disabled | boolean | false |
Accessibility
- Base UI Switch:
role="switch", toggles with Space and Enter, state inaria-checked. - Label it:
htmlFor/idwith a visible Label, oraria-labelwhen the context makes text redundant.