Toggle
A two-state button that can be either on or off.
Installation
bash
npx shadcn@latest add @redpanda/togglebash
pnpm dlx shadcn@latest add @redpanda/togglebash
yarn dlx shadcn@latest add @redpanda/togglebash
bunx shadcn@latest add @redpanda/togglebash
nubx shadcn@latest add @redpanda/togglebash
aube dlx shadcn@latest add @redpanda/toggleWhen 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>witharia-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-labelfor icon-only toggles. Icon-only toggles without a label are unreadable to screen readers. onPressedChangeuses the Base UI signature(pressed: boolean, eventDetails) => void—eventDetailslets you inspect the change reason or callpreventDefault(). Single-argument callbacks remain compatible.