Switch
switchA 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.
"use client";
import { useState } from "react";
import { Switch } from "@/components/forme/switch/switch";
export function SwitchDemo() {
const [on, setOn] = useState(true);
return (
<div className="flex flex-col gap-5">
<div className="flex flex-col gap-3">
<Switch checked={on} onCheckedChange={setOn} label="Enable notifications" />
<Switch checked={false} onCheckedChange={() => {}} label="Off" />
<Switch checked disabled onCheckedChange={() => {}} label="Disabled" />
</div>
<div className="flex flex-col gap-3">
<Switch label="Email me about releases" defaultChecked />
<Switch label="Weekly digest" />
<Switch label="Disabled, unchecked" disabled />
</div>
<div className="flex flex-col gap-3">
<Switch aria-label="Compact, no visible label" defaultChecked />
<div className="max-w-64 rounded-xl border border-border bg-card p-4">
<Switch
label="Send me a summary of everything that happened in the workspace this week"
defaultChecked
/>
</div>
</div>
</div>
);
}Install
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
SegmentedControlsays 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.
| Prop | Type | Default | Description |
|---|---|---|---|
label | React.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"andaria-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.
Related


Checkbox
A single choice with a visible label wired to it for a screen reader. An indeterminate state for a select-all with only some rows picked, a description read as a description rather than folded into the name, a destructive variant, and a mark that draws itself in.
forms

Radio group
A choice of exactly one option. The selected dot travels between options on a spring, each option carries its own label and optional description, and arrow keys move the selection in the direction the options are laid out.
forms

Select
A choice from a list too long for radio buttons. Grouped with labels, an inline check on the selected option, typeahead and arrow-key navigation from the Base UI select primitive, and a label in the trigger that rolls in the direction of the list — down for a later option, up for an earlier one.
forms