Skip to content

Copy Button

New

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.

  • React 19
  • Tailwind CSS 4

Added Nov 8, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

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

api-key-row.tsx

CopyButton

<button>
PropTypeDefaultDescription
aria-labelstring—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.
classNamestring—
busybooleanfalseThe 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"
valuestring—The text to copy. An empty value with no getValue disables the button.
getValue—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).
timeoutnumber2000How long the result (check or X) shows, in ms. Default 2000.
onCopy—Runs after the clipboard has the text, with the text.
onCopyError—Runs when the copy fails: no Clipboard API, the browser refused, or getValue failed.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

AnimatedCopyIcon

<svg>
PropTypeDefaultDescription
variant"bulk""duotone""solid""stroke""twotone"—stroke (default): 1.5 strokes. solid: the body filled, inner details cut through. duotone: a 40% fill under the stroke. twotone: the details at 40%. bulk: the body filled at 40% with no outline, the details at full color.
corners"round""sharp"—round (default): round caps and joins, soft corners. sharp: square caps, miter joins.
trigger"hover""none"—hover (default) plays once per hover or keyboard focus of the control around the icon.
playnumber—Plays once each time this number changes (a new notice, a saved form).
state"copied""error""idle""idle"copied draws a bare check, error a bare cross with a wobble. Default idle.
statusColorsbooleanfalseStatus colors for the marks: the check takes the success color and the cross the destructive color (the -soft-foreground tokens). Default false: both take the text color.
...props<svg> attributes—Every other attribute goes to the <svg>, with a ref.
  • 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.
  • For an action that does not copy, use a Button.
EnterCopies the value.
SpaceCopies the value.

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).

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

Built with

Installs with Copy Button

Components
Button
  1. AddedCopy Button, with Button.
Open the release