Skip to main content
03 / Components

Switch

Toggles a single setting on or off. State changes are immediate and persistent.

Preview

Off

States

Switch is binary by design. The visible states are off, on, disabled-off, and disabled-on. The disabled states are non-interactive but legible.

off
on
disabled · off
disabled · on

Usage

Do

Use Switch for binary settings that take effect immediately on toggle.

Don’t

Use Switch for actions that need confirmation or a save step — use a Button.

Do

Pair every Switch with a clear, persistent label describing what the setting controls.

Don’t

Rely on the on/off visual alone to convey what the toggle does.

Do

Use a real <button role="switch"> element so screen readers announce the role correctly.

Don’t

Reskin a checkbox or radio as a switch — the semantics differ.

Code

1const [on, setOn] = useState(false)
2
3<Switch.Root checked={on} onCheckedChange={setOn} className="lex-switch">
4 <Switch.Thumb className="lex-switch__thumb" />
5</Switch.Root>

Design tokens

TokenUsage
--color-surface-2Track background — off state
--color-accentTrack background + border — on state
--color-textThumb fill — off state
--color-bgThumb fill — on state
--color-borderTrack border — off state
--lex-radius-pillTrack and thumb shape
--transition-fastBackground and border transitions
--transition-baseThumb translate transition

Accessibility

Switch implements the WAI-ARIA switch pattern via Radix. The trigger is a real <button> with role="switch" and aria-checked reflecting the state. Always pair with an accessible name — either visible text or aria-label.

Space/EnterToggle the switch
TabMove focus to the next focusable element
Shift + TabMove focus to the previous focusable element