Toggle
A two-state button that can be either on or off.
Made by shadcnInstallation
Loading component...
When to use
Toggle provides a two-state button control. Use this decision tree:
Usage
import { Toggle } from "@/components/ui/toggle"<Toggle>Toggle</Toggle>Examples
Default
Loading component...
Outline
Loading component...
With Text
Loading component...
Small
Loading component...
Large
Loading component...
Disabled
Loading component...
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. onPressedChangeis the Radix-style single-argument(pressed: boolean) => void.
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 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
- patchv0.3.1**Accordion** - `AccordionTrigger` now shows `cursor-pointer` on hover.#112
Built by malinskibeniamin. The source code is available on GitHub.