UI.MD

Switch

A toggle switch for boolean settings with default and compact size variants.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/switch.json

Usage

import { Switch } from "@/components/ui/switch"

Examples

Default

Small

API Reference

PropTypeDefaultDescription
size"sm" | "default""default"Track size. default is 20×32px; sm is a compact 16×24px.
checkedboolean-Controlled on/off state. Pair with onCheckedChange.
defaultCheckedbooleanfalseInitial state when uncontrolled.
onCheckedChange(checked: boolean) => void-Called with the new state whenever the switch is toggled.
disabledbooleanfalsePrevents interaction and dims the control.
namestring-Name submitted with the owning form's data.
valuestring"on"Value submitted with the form when the switch is on.