skrewww

Forms

Switch

Switch is a boolean settings control for immediate on/off changes — not a substitute for Checkbox in forms.

Value (Off/On) × State — 8 variants

betaReact AvailableFigma AvailableDocs Partial
React last updated
2026-07-13
Documentation last updated
2026-06-01
Accessibility target
WCAG 2.2 AA (target)
Version
0.2.0-beta

Known open questions

  • Switch thumb travel uses temporary spacing tokens pending Figma alignment property confirmation.
  • Switch surfaces remain functionally flat in Gradient/Glass modes.

Live preview

Switch is for immediate settings changes — not form agreement or multi-select.

Off / On / Disabled

Off by default
On by default
Disabled

When should a Switch be used?

Settings-oriented example

Email notifications
Weekly digest
Product announcements

Purpose

Toggle a setting on/off with immediate effect (no separate form submit required).

Anatomy

Switch = role=switch button + track + thumb + visible label.

Variants and states

off · on · disabled

When to use

Settings that apply instantly when toggled (notifications, dark mode, feature flags).

When not to use

A choice that only takes effect after a form submission (use Checkbox).

Accessibility

Renders as role="switch" with aria-checked, not a plain checkbox.

Keyboard behavior

Space and Enter activate the native button, which toggles aria-checked through click handling. type="button" prevents form submission.

Common mistakes

Using Switch for a setting that actually requires a form submit to take effect.

Properties

Value × State as variants. Label (text). Thumb position driven by the track's alignment property, not hardcoded coordinates.

What is the difference between Checkbox and Switch?

Checkbox records a choice that usually submits with a form. Switch applies a setting immediately, such as notifications or theme preferences.

Tokens used

semantic/border/strongsemantic/action/primarysemantic/surface/defaultsemantic/focus-ring

Component API

PropTypeDefaultDescription
labelstringAccessible name via aria-labelledby.
checkedbooleanControlled on state.
defaultCheckedbooleanInitial uncontrolled on state.
disabledbooleanfalsePrevents toggling.

React example

Copy React example
import { Switch } from "@/components/ui/Switch";

export function Example() {
  return <Switch label="Email notifications" defaultChecked />;
}