Skip to content

Inputs

Switch

A toggle for settings that take effect immediately, like turning on two-factor sign-in or auto-reminders. It comes in three sizes, can show its label and a description, and stays a plain button with role="switch" underneath.

On this page
Email clients 3 days before and after the due date.
Adds a Pay now button to every invoice.
A Monday digest of paid and overdue invoices.

Usage

components/ui/switch.tsx
import { Switch } from "@/components/ui/switch"; export function Example() {  return <Switch label="Auto-send reminders" showLabel defaultChecked />;}

Examples

Settings list

Email clients 3 days before and after the due date.
Adds a Pay now button to every invoice.
A Monday digest of paid and overdue invoices.

Sizes

Visible label

label is always the accessible name. Add showLabel to print it next to the switch.

Disabled

Available on the Business plan.
Required by your organisation.

Props

  • labelrequiredstringdefault: —Accessible name; also the visible label with showLabel or description.
  • showLabelbooleandefault: falsePrint the label next to the switch.
  • descriptionReactNodedefault: —Second line under the label. Implies showLabel.
  • labelPosition"end" | "start"default: "end"start puts the label first and spreads the row, for settings lists.
  • checked / defaultCheckedbooleandefault: falseControlled or initial state.
  • onChange(on: boolean) => voiddefault: —Called with the new state.
  • size"sm" | "md" | "lg"default: "md"Track 28, 36 or 44px wide.
  • disabledbooleandefault: —Prevents toggling and dims the row.
  • namestringdefault: —Submits “on” under this name when checked.
  • idstringdefault: —Id of the switch button. Generated when omitted.

Accessibility

  • A <button role="switch"> with aria-checked: Space and Enter toggle it, and screen readers say “on” or “off”.
  • When the label is visible it's a real <label> linked by aria-labelledby, and clicking it toggles the switch.
  • The description is linked with aria-describedby.
  • Use a switch only for changes that apply immediately; inside a form that needs a Save button, use a Checkbox.
  • The thumb position, not only the track color, shows the state, so it reads in every accent.

Suggested