---
title: "Toggle"
description: "A button that stays on or off, such as Bold, Mute, or Pin. It has two looks, four sizes, and the same shape as Button."
url: https://gelatinui.com/components/toggle
markdown_url: https://gelatinui.com/components/toggle.md
access: free
install: "npx shadcn@latest add @gelatin-ui/toggle"
registry_item: https://gelatinui.com/r/toggle.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Toggle

> A button that stays on or off, such as Bold, Mute, or Pin. It has two looks, four sizes, and the same shape as Button.

Page: https://gelatinui.com/components/toggle

## When to use it

Best for: A button that stays on or off, such as bold, mute, or pin, with the effect at once.

- Use it for a button that stays on or off and acts at once.
- Use `variant="outline"` to sit level with a field.
- Use `pressed` and `onPressedChange` to control it, or `defaultPressed` to leave it on its own.

## When not to use it

- For a setting with Save, use a [Switch](https://gelatinui.com/components/switch.md).
- For a choice in a form, use a [Checkbox](https://gelatinui.com/components/checkbox.md).
- To start an action, use a [Button](https://gelatinui.com/components/button.md).
- To pick one of several values, use a [Segmented Control](https://gelatinui.com/components/segmented-control.md).

## Notes for agents

- It has no form value.
- Keep the label the same in both states. Change only the icon, with a `render` function that reads `state.pressed`.
- An icon-only toggle needs an `aria-label`. A Tooltip may show the same name.
- Call `eventDetails.cancel()` in `onPressedChange` to keep the old state.
- `hit-area` grows the target to 44 × 44. For toggles closer than 16px, put `hit-area-row` on the row.

## Anatomy

```text
Toggle
```

## API reference

### Toggle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `rounded` | `"default" \| "full"` | "default" |  |
| `className` | `string` |  |  |
| `variant` | `"default" \| "outline"` | "default" | `default`: no rest fill. `outline`: the field surface with an edge. |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` | "default" | Height 24, 28, 32, or 36px. |

Also takes every prop of Base UI `Toggle`: https://base-ui.com/react/components/toggle

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Toggle | `toggle` | `data-icon`, `data-pressed` |  |  |

## Usage

An icon-only toggle needs an `aria-label`. Keep the name the same in both states and change only the icon.

```tsx title="bold-toggle.tsx"
import { TextBIcon } from "@phosphor-icons/react/ssr";

import { Toggle } from "@/components/ui/toggle";

export function BoldToggle() {
  return (
    <Toggle aria-label="Bold">
      <TextBIcon />
    </Toggle>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/toggle
```

It adds 9 registry items: 6 files, 1457 lines, and the npm packages `@base-ui/react`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Button](https://gelatinui.com/components/button.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Segmented Control](https://gelatinui.com/components/segmented-control.md)
- [Button](https://gelatinui.com/components/button.md)
- [Animated Eye Icon](https://gelatinui.com/components/animated-eye-icon.md)
- [Toggle Group](https://gelatinui.com/components/toggle-group.md)
- [Checkbox](https://gelatinui.com/components/checkbox.md): Pick Checkbox for a choice in a form that a Save or Submit button sends.
- [Switch](https://gelatinui.com/components/switch.md): Pick Switch for a named setting in a settings list that takes effect at once.

## Keyboard

| Keys | Action |
| --- | --- |
| Enter | Turns the toggle on or off. |
| Space | Turns the toggle on or off. |

## Accessibility

It is a Base UI Toggle: a button with `aria-pressed`.

It has no form value. Use a Switch or a Checkbox in a form.

`hit-area` grows the target to 44 × 44. For toggles closer than 16px, put `hit-area-row` on the row.
