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

For a setting that takes effect the moment it is flipped. A switch has no Save step, so use a checkbox in a form when the change needs confirming first.

Small

The 16x24px track, for dense rows and menus. Step the label down with it (text-xs here) or the control looks undersized against its own text.

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.