Components
A control that allows the user to toggle between checked and not checked.
Playground
Field and FieldLabel for proper layout and labeling. The hit area extends invisibly past the 32×18px track, so the target stays comfortable on touch screens.import { Switch } from "@workspace/ui/components/switch"
import { Field, FieldLabel } from "@workspace/ui/components/field"
<Field orientation="horizontal">
<Switch id="airplane-mode" />
<FieldLabel htmlFor="airplane-mode">Airplane Mode</FieldLabel>
</Field>default (32×18px) and sm (24×14px). Set size on Switch; the sm size suits dense layouts like table rows and toolbars.<Field orientation="horizontal"> <Switch id="switch-sm" size="sm" defaultChecked /> <FieldLabel htmlFor="switch-sm">Small switch</FieldLabel> </Field> <Field orientation="horizontal"> <Switch id="switch-default" defaultChecked /> <FieldLabel htmlFor="switch-default">Default switch</FieldLabel> </Field>
FieldContent and add a FieldDescription for helper text. Placing the switch after the content pushes it to the end of the row — the common settings-list layout.Focus is shared across devices, and turns off when you leave the app.
<Field orientation="horizontal">
<FieldContent>
<FieldLabel htmlFor="share">Share across devices</FieldLabel>
<FieldDescription>
Focus is shared across devices, and turns off when you leave the app.
</FieldDescription>
</FieldContent>
<Switch id="share" defaultChecked />
</Field>Field in its FieldLabel to turn it into a clickable card — the label border highlights with primary while the switch is checked. Use FieldTitle for the heading inside the card.<FieldGroup>
<FieldLabel htmlFor="switch-2fa">
<Field orientation="horizontal">
<FieldContent>
<FieldTitle>Multi-factor authentication</FieldTitle>
<FieldDescription>
Require a second confirmation step when signing in.
</FieldDescription>
</FieldContent>
<Switch id="switch-2fa" defaultChecked />
</Field>
</FieldLabel>
<FieldLabel htmlFor="switch-backup">
<Field orientation="horizontal">
<FieldContent>
<FieldTitle>Automatic backups</FieldTitle>
<FieldDescription>
Back up your workspace every night at 2 AM.
</FieldDescription>
</FieldContent>
<Switch id="switch-backup" />
</Field>
</FieldLabel>
</FieldGroup>defaultChecked for uncontrolled switches, or checked and onCheckedChange to control the state. Unlike Checkbox, the callback receives a plain boolean — there is no indeterminate state.const [checked, setChecked] = React.useState(false)
<Field orientation="horizontal">
<Switch
id="notifications"
checked={checked}
onCheckedChange={setChecked}
/>
<FieldLabel htmlFor="notifications">
{checked ? "Notifications on" : "Notifications off"}
</FieldLabel>
</Field>disabled prop to prevent interaction and add data-disabled to the Field so the label dims with the track. The checked state is preserved, so a disabled switch can stay on.<Field orientation="horizontal" data-disabled> <Switch id="bluetooth" disabled /> <FieldLabel htmlFor="bluetooth">Bluetooth</FieldLabel> </Field> <Field orientation="horizontal" data-disabled> <Switch id="wifi" disabled defaultChecked /> <FieldLabel htmlFor="wifi">Wi-Fi</FieldLabel> </Field>
aria-invalid on the switch and data-invalid on the field wrapper to show the invalid styles — a destructive border and ring on the track, and destructive text on the label.<Field orientation="horizontal" data-invalid> <Switch id="terms" aria-invalid /> <FieldLabel htmlFor="terms">Accept terms and conditions</FieldLabel> </Field>
<FieldGroup dir="rtl" className="gap-3">
<Field orientation="horizontal">
<Switch id="airplane-rtl" defaultChecked />
<FieldLabel htmlFor="airplane-rtl">وضع الطيران</FieldLabel>
</Field>
<Field orientation="horizontal">
<Switch id="notifications-rtl" />
<FieldLabel htmlFor="notifications-rtl">تفعيل الإشعارات</FieldLabel>
</Field>
</FieldGroup>defaultChecked or controlled via checked + onCheckedChange. Inside a form it submits value under name like a native checkbox. The size prop is the only local addition.| Prop | Type | Default |
|---|---|---|
| size | "sm" | "default" | "default" |
| checked | boolean | — |
| defaultChecked | boolean | false |
| onCheckedChange | (checked: boolean) => void | — |
| disabled | boolean | — |
| required | boolean | false |
| name | string | — |
| value | string | "on" |
Tokens used
8 design tokens consumed by the Switch component.
--primary
Primary
--primary-foreground
Primary Foreground
--input
Input
--background
Background
--foreground
Foreground
--ring
Ring
--destructive
Destructive
--spacing
Spacing unit (4px)