Switch

A control that allows the user to toggle between checked and not checked states.

Installation

$ npx shadcn@latest add "/r/switch.json"

Usage

With Label

Disabled State

Props

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"The size of the switch.
checkedboolean-The controlled checked state of the switch.
defaultCheckedboolean-The default checked state when initially rendered.
onCheckedChange(checked: boolean) => void-Event handler called when the checked state changes.
disabledbooleanfalseWhether the switch is disabled.
classNamestring-Additional CSS classes to apply to the switch.