Switch
Direct on-or-off preferences with native form state, labels, sizes and reduced-motion support.
Purpose
Use Switch for a direct on/off preference whose change is understood as enabling or disabling a setting.
Settings toggles
Installation
With the Siteplane registry alias configured, add the component and import the installed source from your app.
CLI
pnpm dlx shadcn@4.16.1 add @siteplane/switchImport
import { Switch } from "@/components/ui/switch";
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Label } from "@/components/ui/label";Need the machine-readable source metadata? View registry JSON.
Usage
Switch is for a setting that can be turned on or off immediately. Use Checkbox for form selection.
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
export function Example() {
return <Label><Switch defaultChecked />Email notifications</Label>;
}Examples
States, sizes, field labels, errors, form integration and settings patterns are props and compositions of the same primitive.
States
Sizes
With label and description
Field error
Form integration
Settings and card patterns
API Reference
The reference lists the source-owned exports and props that are easy to miss in visual examples. Inherited Base UI props remain available unless the wrapper narrows them.
Switchaccepts controlledchecked, uncontrolleddefaultChecked,onCheckedChange,disabled,readOnly,required,name,valueand Base UI switch props.size="sm" | "default" | "lg" | "xl"overrides the nearestSiteplaneUIProvidercontrol size.- The native control mirrors checked, disabled and invalid state through Base UI attributes and form participation.
- Every size keeps a consistent 2 px inset between track and thumb without changing the outer track dimensions.
- Track radius scales with control size through the existing provider-derived radius tokens, and the thumb inherits the same radius, including
radius="none".
Motion
Component motion uses the shared Siteplane motion contract. See the global motion guide for provider setup, tokens and reduced-motion behavior.
- The thumb translates and stretches through the native Siteplane Switch motion contract; hover and press feedback stay inside the primitive.
- Reduced motion keeps the checked state immediate and removes non-essential transition.
Accessibility
- Pair every Switch with a visible clickable label or provide a precise accessible name.
- Use Switch for settings, Checkbox for form agreement or multi-select, and never communicate state by color alone.
- Disabled, read-only and invalid state need supporting context when the reason is not obvious.
Implementation Guidance
- Use only the documented sizes or provider default.
- Keep label and control as one clickable setting row without nesting unrelated actions.
- Do not rebuild the switch track or thumb from raw elements.