Skip to content
Redpanda UI
Esc
↑↓navigate↵open⌘Jpreview
Made by shadcn
Edit on GitHub

Toggle

A two-state button that can be either on or off.

Installation

bash
npx shadcn@latest add @redpanda/toggle
bash
pnpm dlx shadcn@latest add @redpanda/toggle
bash
yarn dlx shadcn@latest add @redpanda/toggle
bash
bunx shadcn@latest add @redpanda/toggle
bash
nubx shadcn@latest add @redpanda/toggle
bash
aube dlx shadcn@latest add @redpanda/toggle

When to use

Toggle provides a two-state button control. Use this decision tree:

Usage

tsx
import { Toggle } from '@/components/ui/toggle';
tsx
<Toggle>Toggle</Toggle>

Examples

Default

Outline

With Text

Small

Large

Disabled

Props

Keyboard interactions

Key Action
Tab to the toggle Focus lands on the toggle.
Space / Enter Toggles between pressed / unpressed.

Accessibility

  • Renders as a real <button> with aria-pressed="true" | "false" — use it for on/off visual states (bold, italic, mute) rather than for navigation or mutually-exclusive selection (use Tabs / RadioGroup instead).
  • Base UI also sets the compat data-state="on" | "off" attribute so existing Tailwind selectors keep working.
  • Always provide a label — either visible text inside the toggle, or aria-label for icon-only toggles. Icon-only toggles without a label are unreadable to screen readers.
  • onPressedChange uses the Base UI signature (pressed: boolean, eventDetails) => void — eventDetails lets you inspect the change reason or call preventDefault(). Single-argument callbacks remain compatible.

Credits

  • We use Base UI for the toggle component.
  • We take our inspiration from Shadcn UI for the toggle style.

Recent changes

  • patchv1.2.0Pin shipped dependency floors to the version we develop against. Registry items now declare ranges like `^5.1.9` (the actual installed version) instead of collapsing to `^5.0.0`, so consumers start on the known-tested baseline while caret semantics still allow any compatible release within the same major.#133
  • minorv1.1.0Theme docs refresh, readability pass on semantic foregrounds, and consumer-facing Base UI regression fixes.#121
  • minorv1.0.0Post-Base-UI polish. Public API unchanged.#116
  • majorv1.0.0Migrate every Radix-based primitive to `@base-ui/react@^1.4.0` (Base UI).#114
  • patchv0.3.1## 🚧 Updated#112
See full history →

Last updated on

Was this page helpful?