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

# 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, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `CopyButton`.

## When to use

- 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.
- Also called: copy to clipboard.

## 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 Copy button on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-copy-button.json --yes
```

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

## Usage

```tsx
import { CopyButton } from '@/components/ui/goop/copy-button';
import { TextInput } from '@/components/ui/goop/text-input';

<>
  <div className="flex w-full items-center gap-2">
    <TextInput
      aria-label="API key"
      readOnly
      value="key_live_7Hq2xV9mK4tR8wN3cL6p"
      className="min-w-0 flex-1 text-ellipsis"
    />
    <CopyButton value="key_live_7Hq2xV9mK4tR8wN3cL6p" label="Copy key" variant="outline" size="lg" />
  </div>
  <CopyButton value="https://example.com/invite/7f3a9c" label="Copy invite link" iconOnly variant="outline" size="md" />
</>
```

- Fits: settings (its recipe).
- Also known as: CopyToClipboard, ClipboardButton, Clipboard.
- Put a CopyButton at the end of any value a person will paste elsewhere — a key, a link, an id — and let it confirm in place; use `ChatMessageCopy` in a chat message, and never a Toast for the confirmation.
- width, motion: add no class for these.

## API reference

### Options

- `value: string` — What is copied: the exact text put on the clipboard.
- `label?: string = 'Copy'` — The words at rest; with `iconOnly`, the button's name — say what is copied ("Copy API key").
- `copiedLabel?: string = 'Copied'` — The words once the value is on the clipboard.
- `failedLabel?: string = 'Couldn’t copy'` — The words when the copy failed.
- `iconOnly?: boolean = false` — The glyph alone, on the theme's IconButton; `label` names it.
- `variant?: 'ghost' | 'outline' = 'ghost'` — `ghost` (no fill at rest) or `outline` (the surface fill on its ring).
- `size?: 'sm' | 'md' | 'lg' = 'sm'` — `sm` 24 px, `md` 28 px, `lg` 32 px (beside a `TextInput`).
- `onCopy?: (value: string) => void` — Called with `value` once it is on the clipboard.
- `onClick?: (event: MouseEvent) => void`
- `disabled?: boolean`

## Keyboard

- Enter: copy the value; the focus stays on the button
- Space: copy the value; the focus stays on the button

## Accessibility

- The part itself answers the keys above.
- hover, active, focus-visible: the browser's own (:hover, :active, :focus-visible): write nothing
- 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

- [Text input](/themes/trail/components/text-input): A single-line field for free words, such as a name, a title or an email.
- [Menu button](/themes/trail/components/menu-button): The button a menu opens from, shown as words, a workspace's tile or an icon.
- [Color mode toggle](/themes/trail/components/color-mode-toggle): The app's switch between light and dark, as a button or a menu.
- [Link](/themes/trail/components/link): A text link to another page or place, in running text or on its own.
