Skip to content
Browse docs and components

Switch

switch

A control for a setting that takes effect immediately, with a label wired to it for a screen reader. Optional on and off text inside the track, and the thumb travels on a single transform so the motion stays smooth.

Responsive

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 wired to it.
onLabelstring—Text shown inside the track, either side of the thumb. Both are optional.
offLabelstring—

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

Accessibility

  • The label is tied with aria-labelledby, because the switch is a <button> and a <label> may not wrap one.

Motion

  • The thumb travels on the standard duration; the track's colour changes at once.