Skip to content

Toggle

A two-state button on Base UI Toggle.

For one setting that is on or off and takes effect at once, such as a toolbar option. For a setting in a form use @khaeli/switch or @khaeli/checkbox, and for several toggles that belong together @khaeli/toggle-group.

Variants

Sizes

With icon

Icon only

States

Controlled

Not starred

Installation

npx shadcn@latest add @khaeli/toggle

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
  • class-variance-authority ^0.7.1

Keyboard

SpaceEnter
Presses or releases the toggle.
Tab
Moves focus to the toggle. A disabled toggle is a native disabled button: it leaves the tab order.

Accessible name

  • The name is the toggle's text. An icon-only toggle needs an aria-label.
  • The state is aria-pressed, set by the item. Keep the name the same in both states (Star the project, not Unstar), or the state is said twice.

Registry JSON

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