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

Switch

A toggle that turns a single setting on or off right away, like enabling a feature, with a sliding thumb that shows its current state.

Installation

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

Disabled

When to use

Switches provide binary toggle controls. Use this decision tree:

Usage

tsx
<Switch />

Props

Examples

Default

Advanced Label

Card style

Settings panel

Form

Keyboard interactions

Key Action
Tab to the switch Focus lands on the switch.
Space Toggles checked state.
Enter Submits the surrounding form — does not toggle the switch (Space is the dedicated toggle key).

Accessibility

  • Base UI renders the switch as a real <button role="switch"> with aria-checked. It also sets the Radix-compat data-state="checked" | "unchecked" attribute so existing selectors keep working.
  • Always pair with a visible <Label htmlFor> — switches without labels are ambiguous (“on for what?”).
  • Use a switch for immediate-effect binary settings (notifications on/off, theme toggle). For binary form values submitted alongside other fields prefer a Checkbox — its ARIA semantics are better understood by assistive tech.
  • onCheckedChange is the Radix-style single-argument (checked: boolean) => void.

Credits

  • We use Base UI for the switch component.
  • We take our inspiration from Shadcn UI for the switch 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
  • minorv0.3.0Add theme-provider component to the registry with documentation and tests. Includes playground type improvements (export RegistryItem, remove as-const boilerplate) and docs site dark mode border color fix.#109
See full history →

Last updated on

Was this page helpful?