Switch
A control that allows the user to toggle between on and off states.
Installation
bash
npx shadcn@latest add switchImport
import { Switch } from "@/components/ui/switch"import { Label } from "@/components/ui/label"Default
With label
Checked by default
Disabled
Settings panel
Props
PROPTYPEDEFAULTDESCRIPTION
checkedboolean—Controlled checked statedefaultCheckedbooleanfalseInitial state (uncontrolled)onCheckedChange(checked: boolean) => void—Called when toggleddisabledbooleanfalseDisables the switchrequiredbooleanfalseMarks as required in a formnamestring—Form field nameAccessibility
- Pressing Space toggles the switch
- Always pair with a
Labelusing matchingid/htmlFor