Base · Forms
Switch
Turns a single setting on or off, immediately.
HTML / JSDraftReactStableReact NativeDraftSwift (SwiftUI)PlannedGodotPlannedVueDraftSvelteDraftSolidDraft
Reviewed
Props
tsx
import { Switch } from "@/components/ui/switch"
import { Label } from "@/components/ui/label"
<Label className="gap-3 font-normal">
Notify me on delivery
<Switch defaultChecked={true} />
</Label>Overview
A switch controls one setting and applies the change the moment it is flipped, with no save step. It behaves like a physical light switch.
When to use
- For a setting that takes effect right away, such as enabling notifications.
- In settings lists, with the label on the left and the switch on the right.
When not to use
- When the change only applies after a submit: use Checkbox.
- To choose between two unrelated options: use Radio Group or Toggle Group.
Anatomy
Track
Pill-shaped. Brand colored when on, muted when off.
Thumb
Slides to the trailing edge when on.
Label
Names the setting, not the state: “Notifications”, not “Turn on notifications”.
Props
The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | true | Whether the switch is on. |
| size | "sm" | "default" | default | Track size. |
| disabled | boolean | false | Prevents interaction and dims the control. |
| label | string | Notify me on delivery | The text next to the switch. |
| onCheckedChange | function | – | Called with the new state. `onchange` in Dioxus. |
States
- Off
- Muted track, thumb at the leading edge.
- On
- Brand track, thumb at the trailing edge.
- Focus-visible
- 3px ring in color.border.focus.
- Disabled
- 50% opacity; not focusable.
Accessibility
Role: switch
| Keys | Action |
|---|---|
| Space/Enter | Toggles the switch. |
| Tab | Moves focus to the next control. |
- State is conveyed by position as well as color.
- The thumb animation is removed when the user prefers reduced motion.
Design tokens
Change any of these in Foundations and this component follows, in every language.
Platform notes
- HTML / JS
- Draft
- A <button role="switch">; pdc.js flips aria-checked on click, Space or Enter and fires a bubbling `change` event.
- React
- Stable
- Matches the contract with no platform differences.
- React Native
- Draft
- Custom-drawn rather than the OS switch, so it matches the brand on iOS and Android. Controlled: pass `checked` and `onCheckedChange`.
- Swift (SwiftUI)
- Planned
- Not built in Swift yet.
- Godot
- Planned
- Not built in Godot yet.
- Vue
- Draft
- Usage snippet only; same props and behavior as the React component.
- Svelte
- Draft
- Usage snippet only; same props and behavior as the React component.
- Solid
- Draft
- Usage snippet only; same props and behavior as the React component.