Redpanda UIRedpanda UI

Switch

A control that allows the user to toggle between checked and not checked.

Made by shadcn

Installation

Loading component...

Disabled

Loading component...

When to use

Switches provide binary toggle controls. Use this decision tree:

Usage

<Switch />

Props

Examples

Default

Loading component...

Advanced Label

Loading component...

Card style

Loading component...

Settings panel

Loading component...

Form

Loading component...

Keyboard interactions

KeyAction
Tab to the switchFocus lands on the switch.
SpaceToggles checked state.
EnterSubmits 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 b…#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 →
Built by malinskibeniamin. The source code is available on GitHub.

On this page