Switch
Turns a single option on or off, taking effect immediately.
Installation
npx shadcn@latest add https://qure-ui.qure.ai/r/switch.jsonUsage
import { Switch } from '@/components/ui/switch'<Label><Switch defaultChecked /> Auto-refresh worklist</Label>Switch or Checkbox?
A switch takes effect the moment it is flipped. A checkbox is a selection you confirm later with a button. If your form has a Save button, the control is probably a checkbox — and if flipping the switch cannot actually change anything until something else happens, the switch is lying about when it applies.
A switch is also wrong for a choice between two named things. "Sagittal / Coronal" is a pair of options, not an on and an off; that is a radio group or a toggle group, where both choices are visible and labelled.
With a label
Wrapping the switch in a Label is the shortest correct form; htmlFor with the switch's id
works too, because Base UI puts that id on the hidden input rather than on the rendered span
(unless you set nativeButton). Either way the text becomes part of the hit target, which a
40×24 track needs.
States
Off, on, and both disabled. Disabled keeps the switch in the DOM and readable rather than hiding the option — "your administrator has fixed this" is information, and a setting that vanishes looks like a bug. Say why it is disabled somewhere near it; the greying alone does not.
A settings panel
Label on the left with htmlFor, control on the right, one line of consequence under each
label — wrapping would put the switch inside the text block. This is where
switches earn their keep: several independent preferences, each applying as soon as it is
touched, with no Save button anywhere in sight.
Controlled
Overlays drawn on the current series.
Pass checked with onCheckedChange when the state lives elsewhere — a viewer preference shared
between panes, or one persisted to the server. Reflect the result near the control, and if the
write can fail, put the switch back and say so rather than leaving it showing a state the server
never accepted.
The design system calls this component Toggle. It is Switch here because in Base UI and
shadcn, Toggle means a pressed-state button and Switch is the on/off track — keeping their
names keeps the primitives predictable.
API Reference
Everything Base UI's Switch accepts. The ones you will reach for:
Prop
Type