---
title: "Copy Button"
description: "A button that copies a value, such as a key or a link, with one press. Its icon turns into a check for 2 seconds, or a cross when the copy fails."
url: https://gelatinui.com/components/copy-button
markdown_url: https://gelatinui.com/components/copy-button.md
access: free
install: "npx shadcn@latest add @gelatin-ui/copy-button"
registry_item: https://gelatinui.com/r/copy-button.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Copy Button

> A button that copies a value, such as a key or a link, with one press. Its icon turns into a check for 2 seconds, or a cross when the copy fails.

Page: https://gelatinui.com/components/copy-button

## When to use it

Best for: A value that people paste somewhere else: an API key, a link, or a command.

- Use it next to a value that people paste somewhere else: a key, a link, a command.
- Use `getValue` for a value that comes from the server. The button shows a spinner while it waits.
- With text children ("Copy link") the icon takes the leading slot, and the width stays the same.

## When not to use it

- For an action that does not copy, use a [Button](https://gelatinui.com/components/button.md).

## Notes for agents

- Pass the text in `value`, or an async `getValue` for a value from the server.
- After a press, the icon shows a check or an X for 2 seconds, then comes back.

## Anatomy

```text
CopyButton
```

## API reference

### CopyButton

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `aria-label` | `string` |  | Defines a string value that labels the current element. The name of the button. An icon-only button defaults to "Copy"; one with text uses its text. |
| `className` | `string` |  |  |
| `busy` | `boolean` | false | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` | "start" | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` | "ghost" |  |
| `value` | `string` |  | The text to copy. An empty value with no `getValue` disables the button. |
| `getValue` | `function` |  | Gets the text at press time: a value that is costly to build, or that comes from the server (a new token). While its promise runs, the button shows the Button spinner (`pending`). |
| `timeout` | `number` | 2000 | How long the result (check or X) shows, in ms. Default 2000. |
| `onCopy` | `function` |  | Runs after the clipboard has the text, with the text. |
| `onCopyError` | `function` |  | Runs when the copy fails: no Clipboard API, the browser refused, or `getValue` failed. |

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

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| CopyButton | `copy-button` |  |  |  |

## Usage

Pass the text in `value`, or use `getValue` for text from the server. Give an icon-only button a `label` that names the value.

```tsx title="api-key-row.tsx"
import { CopyButton } from "@/components/ui/copy-button";

export function ApiKeyRow({ apiKey }: { apiKey: string }) {
  return (
    <div className="flex items-center gap-2">
      <code className="font-mono text-sm">{apiKey}</code>
      <CopyButton
        value={apiKey}
        aria-label="Copy API key"
        timeout={3000}
      />
    </div>
  );
}
```

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

It adds 27 registry items: 24 files, 3936 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Animated Copy Icon](https://gelatinui.com/components/animated-copy-icon.md)
- [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

- [Button](https://gelatinui.com/components/button.md)
- [Animated Copy Icon](https://gelatinui.com/components/animated-copy-icon.md)
- [QR Code](https://gelatinui.com/components/qr-code.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Enter | Copies the value. |
| Space | Copies the value. |

## Accessibility

Copy Button is a Button, so it renders a `<button>`. An icon-only button gets its name from `label` (default "Copy"). A button with text uses its text. The name never changes after a press.

The icons are `aria-hidden`. While `getValue` waits, the button shows a spinner and sets `aria-busy`. An empty `value` with no `getValue` disables the button.

The default `icon-sm` size is 28px. On a touch screen the touch target grows to 44px (`hit-area`).

## Motion

| Part | Motion |
| --- | --- |
| Icon in | fade · 150ms · ease-out (0, 0, 0.2, 1) · the copy, check, or X icon fades in and grows from 60% |
| Icon out | fade-exit · 90ms · ease-out (0, 0, 0.2, 1) · the icon fades out and shrinks to 60% |
| Press | press · 100ms · ease-out (0, 0, 0.2, 1) · moves down 1px |
