---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Toggle button

A button that stays pressed until it is pressed again, for React and Tailwind CSS. Free, MIT.

Free. Its export: `ToggleButton`.

## Try it

Press it to hold it down, press again to let it up; switch every look and size, words or icon, and disable it.

No notes are filtered: the line under it only says the state.

## When to use

- A button that stays pressed until it is pressed again.
- Also called: toggle.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Toggle button on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing.

```sh
npx shadcn@4.23.1 add @goop/trail-toggle-button
```

```text
Add the Goop Toggle button to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { ToggleButton, ToggleButtonIcon } from '@/components/ui/goop/toggle-button';

<>
  <ToggleButton variant="outline" aria-label="Side panel" defaultPressed>
    <ToggleButtonIcon icon="layout-sidebar-right" pressedIcon="layout-sidebar-right-filled" />
  </ToggleButton>
  <ToggleButton shape="circle" size="lg" aria-label="Teodora Valk" defaultPressed>
    TV
  </ToggleButton>
  <ToggleButton variant="chip" defaultPressed>
    Status
  </ToggleButton>
  <ToggleButton variant="chip">
    Labels
  </ToggleButton>
</>
```

- Fits: record, chat: toolbar.
- Also known as: Toggle.
- height, width, padding, gap, corner, border, background, shadow, text, motion: add no class for these.

## API reference

### Options

- `variant: default | chip | outline = default`
- `size: md | lg = md`
- `shape: pill | circle = pill`
- `asChild?: boolean`
- `pressed?: boolean`
- `defaultPressed?: boolean = false`
- `onPressedChange?: (pressed: boolean) => void`
- `disabled?: boolean`

- State: pressed (pressed / defaultPressed / onPressedChange)

### Parts

- `ToggleButtonIcon` — The toggle's icon, decorative (the toggle carries the name); icon: IconName — A pack icon name (an outline icon, or a filled one): a star is `carambola`; pressedIcon?: IconName — The pack icon drawn instead while pressed; none by default

- Class recipes (cva): toggleButtonVariants (ToggleButton)
- data-slot values (to select a part by): toggle-button, toggle-button-icon

## Keyboard

- Space: toggle
- Enter: toggle

## Accessibility

- The behaviour layer under the part answers keys, focus and dismissal: never write your own.
- hover, active, focus-visible: the browser's own (:hover, :active, :focus-visible): write nothing
- pressed: the attribute aria-pressed
- disabled: the prop disabled

## Motion

- The part sets its own motion: add no transition or animation of your own.

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Toggle group](/themes/trail/components/toggle-group): A row of toggle buttons that act together, one or several pressed, such as a view switch or text formatting.
- [Link](/themes/trail/components/link): A text link to another page or place, in running text or on its own.
- [Copy button](/themes/trail/components/copy-button): A button that copies a value such as a link, a key or a command to the clipboard and says it was copied in place.
- [Menu button](/themes/trail/components/menu-button): The button a menu opens from, shown as words, a workspace's tile or an icon.
