---
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/"
---

# Button

A button with words that runs an action, in several looks and sizes, for React and Tailwind CSS. Free, MIT.

Free. Its export: `Button`.

## Try it

Switch every look, shape and size; change the words; add the icon; make it disabled or busy. Press it (pointer or keyboard) and the count under it goes up, but never while disabled or busy (busy keeps its width and the focus).

Nothing is saved: the press is only counted.

## When to use

- A button with words that runs an action, in several looks and sizes.

## When not to use

- For an icon alone use IconButton, to delete DestructiveButton.

## 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 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-button
```

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

## Usage

```tsx
import { Button, ButtonIcon, ButtonLabel, ButtonEnd } from '@/components/ui/goop/button';
import { useState } from 'react';

function NoteActions({ save }: { save?: () => Promise<void> }) {
  const [saving, setSaving] = useState(false);
  return (
    <>
      <Button variant="ghost" size="md">
        <ButtonIcon icon="plus" />
        <ButtonLabel>Add</ButtonLabel>
      </Button>
      {/* the main action: 28 px on a wide screen, 48 px on a phone */}
      <Button
        loading={saving}
        loadingLabel="Saving"
        onClick={async () => {
          setSaving(true);
          try {
            await save?.();
          } finally {
            setSaving(false);
          }
        }}
      >
        Save
      </Button>
    </>
  );
}
```

- Fits: account, app, board, chat, flow, list, record, schedule, states (their recipes).
- height, width, padding, gap, corner, border, background, shadow, text, motion: add no class for these.

## API reference

### Options

- `variant: primary | outline | ghost | subtle | link | nav | text = primary`
- `shape: pill | rounded = pill`
- `size: sm | md | lg | xl = md`
- `asChild?: boolean = false` — Render the button's look on the one child element instead of a `button` (a link, a menu's trigger).
- `loading?: boolean = false` — The button's action is running: a spinner over its words (the width kept), and no press reaches `onClick` or submits; it keeps the focus.
- `loadingLabel?: string = 'Loading'` — What a reader hears beside the button's words while `loading`.
- `type?: 'button' | 'submit' | 'reset'`
- `onClick?: (event: MouseEvent) => void`
- `disabled?: boolean`

### Parts

- `ButtonIcon` — A glyph in the button; icon: IconName — A pack icon name
- `ButtonLabel` — The button's words, where they carry a type of their own (the quiet rounded button's 450 weight, a sort control's grey words); words without it sit in the button directly
- `ButtonEnd` — The button's trailing run — a glyph after the words (a sort arrow, an outward arrow) or a key hint

- Class recipes (cva): buttonVariants (Button)
- data-slot values (to select a part by): button, button-end, button-icon, button-label, button-spinner

## Keyboard

- Enter: activate
- Space: activate

## Accessibility

- The native element answers the keyboard.
- hover, active, focus-visible: the browser's own (:hover, :active, :focus-visible): write nothing
- expanded: the attribute data-state=open
- open: the attribute data-state=open
- disabled: the prop disabled

## Motion

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

## Responsive behaviour

- The button is as wide as its words wherever it stands; no parent or prop stretches it. One that fills its row takes `className="w-full"`; one that fills it on a phone only, `className="max-narrow:w-full"`.

## 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

- [Icon button](/themes/trail/components/icon-button): A button whose only visible label is one icon, for toolbars, rows and headers.
- [Destructive button](/themes/trail/components/destructive-button): The button for an action that deletes or cannot be undone, marked in the danger colour.
- [Button group](/themes/trail/components/button-group): Joined buttons, and a SplitButton: a main action with its menu.
- [Toggle button](/themes/trail/components/toggle-button): A button that stays pressed until it is pressed again.
