Switch
A toggle for an instant, self-applying boolean, built on Radix Switch. Use it for settings that take effect immediately (notifications, airplane mode); reach for a Checkbox when the choice is submitted with a form.
Installation#
Usage#
usage.tsxTSX
import { Switch } from "@/components/ui/switch"
export function Example() {
return (
<label htmlFor="airplane" className="flex items-center gap-2.5">
<Switch id="airplane" defaultChecked />
Airplane mode
</label>
)
}States#
Off rests on the input fill; on slides the thumb across a brand (accent) track. The thumb carries a shadow so it reads on both states in every theme.
Controlled#
Drive the switch from state with checked and onCheckedChange, or leave it uncontrolled with defaultChecked.
In a settings list#
The common shell: a label and description on the left, the switch trailing right. The whole row is the label, so the full width is the hit target.