Clinia UI

Switch

Turns a setting on or off. The change applies right away.

shadcn docs →

When to use

  • A setting that applies the moment it changes: notifications, single sign-on, a source's sync.

When not to use

  • An option inside a form that's saved with a button: use Checkbox.
  • A pressed state on a toolbar button, such as a filter: use Toggle.
  • A choice between two named options, such as English and French: use Radio Group or Toggle Group.

Install

npx shadcn@latest add @clinia/switch

Anatomy

  1. 1Trackdata-slot="switch"bg-input · data-checked:bg-primary
  2. 2Thumbdata-slot="switch-thumb"bg-background · shadow-sm
  3. 3Labeldata-slot="label"text-sm · font-medium

Clinia rules

  • Off is an input track (3:1) and on is a primary track. Trust never fills the track.
  • The label names the setting (Email notifications), not the state or the action (On, Turn on).
  • size="sm" (16px tall) is for dense settings lists and table rows. Use default everywhere else.

Do and don't

Do name the setting the switch controls.
Don't label it with the state or the action.
Do apply the change as soon as it flips.
Don't put a switch in a form that waits for Save: use Checkbox.

States

off
on
focus
invalid
disabled
disabled · on
size sm

Focus cells apply the component's focus-visible classes statically. Toggle the site theme to review both themes.

Accessibility

Built in

  • Focus-visible shows a solid Trust ring (border-ring ring-3 ring-ring/30); aria-invalid swaps it to a destructive ring.
  • Base UI renders a span with role="switch" and aria-checked, plus a hidden native checkbox so the value submits with the form. In tests, find it with getByRole("switch").

Your responsibility

  • Pair it with a Label (htmlFor = the switch id), or put both in a horizontal Field.
  • If the change can fail, say so right away and put the switch back. Don't leave it showing a state that didn't save.

How to test

  1. Press Tab to reach the switch: the Trust ring appears.
  2. Press Space: it toggles and the setting applies with no Save button.
  3. Click the label: it toggles too.
  4. With a screen reader, it's announced as its label, then switch, then on or off.

API

PropValuesDefaultDescription
size
smdefault
default

sm for dense settings lists and table rows.

All other props come from Base UI Switch.