Skip to content

Switch

A switch on Base UI Switch with a 24px hit area.

For a setting that takes effect at once. In a form that is submitted, use @khaeli/checkbox.

With a label

Sizes

With a description

Disabled

Invalid

Installation

npx shadcn@latest add @khaeli/switch

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

Registry items
npm packages
  • @base-ui/react ^1.7.0

Keyboard

SpaceEnter
Turn the switch on and off.
Tab
Moves focus to the switch. A disabled switch leaves the tab order.

Accessible name

  • It renders an element with role="switch" and aria-checked. Name it with a @khaeli/label whose htmlFor is the switch's id.
  • The name says what is on when the switch is on, and stays the same in both states: Payment reminders, not Turn reminders off.
  • A description or an error is tied to the switch with aria-describedby.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/switch.json