Shadcn Toggle
A two-state button (Toggle) for pressed/unpressed UI controls with aria-pressed and data-state synchronization.
About Shadcn Toggle
What it is. A two-state Toggle button supporting default and outline variants, multiple sizes, icon-only or icon-plus-text children, and controlled (pressed / onPressedChange) or uncontrolled (defaultPressed) state.
How it is built. Manages aria-pressed and data-state="on" | "off" attributes automatically for accessible screen-reader announcements and clean state-driven styling.
When to use it. Use Toggle for standalone binary UI controls (mute, pin, star, bold). When multiple toggles share single- or multi-select group state, use Toggle Group.
For AI agents
Hand your agent this brief or the Markdown page, not a screenshot.
When to use
- Independent two-state toolbar or preference buttons (icon-only or icon + label)
- Controlled (
pressed+onPressedChange) or uncontrolled (defaultPressed) pressed state
When not to use
- Mutually exclusive or coordinated button groups — use Toggle Group
- One-shot action triggers — use Button
Agent notes
- Named export:
import { Toggle } from "@/components/custom/blocks/ToggleBlock" - Always provide
aria-labelwhen rendering icon-only toggles
- Markdown
- /docs-md/nextjs-toggle.md
- Install
npx shadcn@latest add https://avaraui.com/r/toggle.json- Registry name
@avara-ui/toggle, through the shadcn MCP server- Index
- llms.txt lists every page, or add the agent skill once
Props Reference
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
Toggle | pressed | boolean | undefined | The controlled pressed state of the toggle. If provided, the component relies entirely on this value. |
Toggle | defaultPressed | boolean | false | The starting state when the component is uncontrolled. |
Toggle | onPressedChange | (pressed: boolean) => void | undefined | Event handler called when the pressed state of the toggle changes. |
Toggle | variant | "default" | "outline" | "ghost" | "default" | The visual style variant. |
Toggle | size | "sm" | "md" | "lg" | "md" | Adjusts the height, horizontal padding, and text-size of the toggle button. |
Toggle | className | string | undefined | Standard Tailwind CSS overrides. |
Works with other components
- Upgrade to Toggle Group when toggles need coordinated single or multiple selection.
- Pair icon-only
Togglecontrols with Tooltip for keyboard and hover labels. - Use Button for one-off actions rather than persistent on/off state.
How do I make a toggle button with pressed state in React?
Render Toggle and either let it manage itself with defaultPressed, which is false by default, or control it with pressed and onPressedChange. It keeps aria-pressed and data-state in sync, so assistive technology and your CSS can both read the state.
How do I control Toggle state externally?
Pass pressed and onPressedChange for controlled React state. When pressed is provided, Toggle relies entirely on that value. Pass defaultPressed instead if you want the component to manage its own state internally.
Should I use Toggle or ToggleGroup?
Use Toggle for independent binary states, such as muting audio or pinning an item. Use Toggle Group when several items share one coordinated single-choice or multiple-choice value, such as text alignment or a view switcher.
Which Toggle variants and sizes are available?
variant is "default", "outline" or "ghost", and size is "sm", "md" or "lg". The ghost variant works best when you cluster several toggles in a toolbar. Children can be an icon alone or an icon plus text.
How do I label an icon-only Toggle?
Wrap it with Tooltip for a hover and keyboard label. Because the toggle exposes aria-pressed, screen readers announce its on or off state, but an icon-only control still needs an accessible name such as an aria-label.