Skip to content

Switch ​

Turns a setting on or off straight away, with no Save button.

Open in Storybook to try every prop.

When to use ​

  • Settings and preferences that apply as soon as they're flipped, e.g. "Email me when an application arrives".

When not to use ​

  • A yes / no answer saved with a form: use Checkbox. Mixing the two in one form makes people unsure what's saved.

Anatomy ​

PartRequiredNotes
trackYes36 × 20px, fully rounded. Off: black 45%. On: primary.
thumbYes16px white circle, slides 16px.
labelYesBeside the switch. Pressing it flips the switch too.
descriptionNoSmaller text under the label.
messageNoHow saving went: "Saving…", "Saved", or an error.

Properties ​

PropertyTypeDefaultDescription
modelValuebooleanfalseOn or off.
labelstring—Required.
descriptionstring—
errorTextstring—Overrides status / statusText.
statuserror | success | loading—As the change saves immediately, show how it went.
statusTextstring—
namestring—
disabledbooleanfalse

States ​

StateAppearanceNotes
OffBlack 45% track, thumb at the left.Dark enough to meet 3:1 contrast.
OnPrimary track, thumb at the right.
HoveredOff: black 55% track.Web / desktop only.
Focused2px focus ring, 2px out.Keyboard only.
SavingSpinner and "Saving…" under it.status="loading".
ErrorRed message; put the switch back if the save failed.
Disabled40% opacity.

Spacing and layout ​

  • Switch to label: 8px. The switch sits on the left, like Checkbox, so a column of settings lines up.
  • A list of settings: 16px apart.

Behaviour ​

  • Space or Enter flips it. The thumb slides in 150ms (none with reduced motion).
  • The whole row is pressable: the switch, its label and its description. The description is not part of the accessible name; it stays the description.
  • Save on change. If saving fails, put the switch back and say so.

Accessibility ​

  • role="switch" with aria-checked, named by its <label>; description and status linked with aria-describedby, status announced politely.

Platform adaptation ​

PlatformImplementationDifferences
Web / desktop (Vue)Switch.vueReka UI Switch.
iOS (SwiftUI)—Toggle (switch on the right, as iOS expects).
Android (Compose)—Switch in a row with the label.

Tokens used ​

TokenUsed for
color-primaryOn track
color-whiteThumb
color-focusFocus ring

Do / Don't ​

DoDon't
Label the setting, not the action ("Weekly summary").Write "Turn on weekly summary".
Show "Saving…" and confirm.Leave people wondering whether it saved.

Released under the PolyForm Noncommercial License 1.0.0.