This page as markdown: /switch.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

Switch

Status: stable

Binary on/off toggle for immediate-effect settings. Track fills with the primary tone when checked; the thumb slides on a spring-eased transform (mirrored in RTL). The thumb is white in both states, like every physical toggle, and turns dark only on a near-white track (a dark mode's light primary). Themes can set --theme-switch-thumb-on.

Keywords: switch, toggle setting, on off, form control

Usage

Use Switch for immediate on/off settings that take effect as a persistent preference or mode.

Best practices

Props

Name Type Default Description
checked boolean — Controlled on/off state. Pair with onCheckedChange. Omit for an uncontrolled switch.
defaultChecked boolean false Initial state for an uncontrolled switch.
onCheckedChange (checked: boolean, eventDetails) => void — Fired when the switch is toggled. Note: Base UI passes a second eventDetails arg — not the common (checked) => void, so a single-arg handler must widen its signature.
disabled boolean false Dims the control and ignores user interaction.
readOnly boolean false Prevents toggling while keeping the control fully visible.
required boolean false Marks the switch as required when inside a form.
name string — Identifies the field when the enclosing form is submitted.

Tokens used

input, primary, ring

Motion

Accessibility

Related

Examples

Default (uncontrolled)

import { Switch } from "@sableui/react"

<Switch defaultChecked />

Controlled

import { Switch } from "@sableui/react"

<Switch checked={on} onCheckedChange={setOn} />

Disabled

import { Switch } from "@sableui/react"

<Switch disabled defaultChecked />

With a label

import { Field, Switch } from "@sableui/react"

<Field label="Reduce motion" orientation="horizontal"><Switch defaultChecked /></Field>