Skip to content

Switch

switch

A control for a setting that takes effect immediately, with a label that is part of the click target. The thumb travels on a weighty spring and stretches toward the far side while it is held; the track's colour flips on the frame it is clicked. Sized to sit in a row beside a control, not to read as a status badge.

Install

$npxshadcnadd@forme/switch

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import { Switch } from "@/components/forme/switch/switch";

<Switch label="Email me when a deploy fails" defaultChecked />

When to use

Reach for it

  • A setting that takes effect the moment it changes, with no Save button.

Use something else

  • Options that are only applied when a form is submitted; use a Checkbox.
  • Choosing between two named values that are not on and off — a SegmentedControl says both names.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

Switch

A switch, with its label.

PropTypeDefaultDescription
labelReact.ReactNode—The visible label. Rendered beside the switch and part of the click target.

Also takes every prop of Omit<SwitchRootProps, "children">.

Accessibility

  • The label is a real <label for> attached to Base UI's underlying input, so clicking the text toggles the switch.
  • The visible box carries role="switch" and aria-checked, and Space both toggles it and does not scroll the page.
  • Disabled reads data-disabled: the track dims, the cursor refuses, and the label is muted rather than looking live.

Motion

  • The thumb travels on a spring with high mass, which settles it firmly rather than wobbling, and retargets from where it is if flipped again mid-flight.
  • The press stretch shares that spring and is anchored at the end the thumb is leaving, so it reaches toward the far side.
  • Reduced motion drops the spring and the stretch and commits the travel instantly; the track's colour was never animated.