Controls
<Switch>
<SwitchControl />
<Label>Airplane mode</Label>
</Switch>Installation
npm
pnpm
yarn
bun
npx shadcn@latest add @dotui/switchUsage
Use switch for communicating activation (e.g. on/off states), while checkboxes are best used for communicating selection (e.g. multiple table rows).
import { Label } from '@/components/ui/field'
import { Switch, SwitchControl } from '@/components/ui/switch'<Switch>
<SwitchControl />
<Label>Focus mode</Label>
</Switch>Anatomy
A Switch wraps a SwitchControl (which auto-renders its SwitchIndicator and SwitchThumb) and a Label. Pass a string child for the label shorthand, or omit children for a standalone control with an aria-label.
import { Label } from '@/components/ui/field'
import {
Switch,
SwitchControl,
SwitchIndicator,
SwitchThumb,
} from '@/components/ui/switch'
<Switch>
<SwitchControl>
<SwitchIndicator>
<SwitchThumb />
</SwitchIndicator>
</SwitchControl>
<Label>Focus mode</Label>
</Switch>
<Switch>Focus mode</Switch>
<Switch aria-label="Focus mode" />Value
The switch is on or off. Use defaultSelected for uncontrolled state, or isSelected with onChange to control it.
const [isSelected, setSelected] = React.useState(true)
<Switch isSelected={isSelected} onChange={setSelected}>
Focus mode
</Switch>Examples
Basic
In a Card
Settings Panel
Feature Flags
Notification Preferences
API Reference
Switch
A switch allows a user to turn a setting on or off.
| Prop | Type | Default | |
|---|---|---|---|
"lg" | "md" | "sm" | 'md' | ||
ReactNode | function | — | ||
boolean | — | ||
RefObject<HTMLInputElement | null> | — | ||
boolean | — | ||
boolean | — | ||
boolean | — | ||
function | — | ||
SwitchControl
The control element of a switch.
| Prop | Type | Default | |
|---|---|---|---|
"lg" | "md" | "sm" | 'md' | ||
ReactNode | function | — | ||
SwitchIndicator
SwitchThumb
Last updated on 7/7/2026