Copy buttonNew
Copies on the press: the icon blurs into a self-drawing check, the label morphs to Copied, and a failed copy shakes and says so.
Used forCode blocksShare links & invite codesAPI keys & secrets
Install with the shadcn CLI
Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/copy-button.json. More
Used in 5 blocks
All blocks- WalletA balance you can send from: the balance panel turns into the transfer, the button goes Sending → Sent, and the money visibly leaves.
- ReferralA referral pass that fills as friends join: their faces fly up into its notches, and the last one turns the track into Claim.
- Order statusAn order’s route with a parcel riding it: stops light as it passes, the arrival day rolls, and the carrier’s scans slide in.
- File shareDrop files, watch them upload, and they fold into one share link with an expiry and an optional password.
Templates
Need the whole page?
65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.
Where it’s used
Code blocks
Top-right copy button in syntax-highlighted code specimens.
Share links & invite codes
One-tap copy for URLs and referral tokens.
API keys & secrets
Fast copying of sensitive tokens with visual confirmation.
What it handles for you
Copying to clipboard is a standard action that often gives weak or delayed feedback. This button gives immediate tactile response with icon morphing and seamless revert.
Checkmark morph
The copy icon crossfades smoothly into a green checkmark on successful copy.
Instant feedback
The copied state lands on the press itself; the clipboard write catches up, and if it is refused the button says Failed and shakes.
Label morph
Icon only, or labelled: "Copy" morphs into "Copied" through TextMorph and the pill eases to its new width.
Self-reverting timer
Returns to idle after timeoutMs (2000ms); pressing again while copied copies again and restarts it.
Accessible announcement
A status region outside the button announces "Copied" (or "Failed"); the icon-only button keeps "Copy" as its name.
Overview
A micro-action button engineered for copying code snippets, markdown blocks, URLs, and API keys. On click, the copy icon smoothly morphs into an animated checkmark, optional labels crossfade without layout jumps, and an accessible screen-reader announcement is dispatched.
States
- idle
- The copy icon, and "Copy" when labelled.
- copied
- On the press: the icon blurs out (scale 0.6, 3px) while an emerald check draws itself in 360ms; the label morphs to "Copied" and the pill eases wider. Back to idle after 2s.
- error
- If the clipboard refuses: red tint, an alert icon, "Failed" and a 380ms shake.
Usage
Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.
Works with
Installs with it
Built on it
- WalletA balance you can send from: the balance panel turns into the transfer, the button goes Sending → Sent, and the money visibly leaves.
- ReferralA referral pass that fills as friends join: their faces fly up into its notches, and the last one turns the track into Claim.
- Order statusAn order’s route with a parcel riding it: stops light as it passes, the arrival day rolls, and the carrier’s scans slide in.
- File shareDrop files, watch them upload, and they fold into one share link with an expiry and an optional password.
- WaitlistA waitlist that is an actual line: you step in at the end with your number over your head, and every friend who joins lets you hop past the person ahead.
Props
- text
- string
- The string to copy.
- label= "Copy"
- string
- Label while idle; also the icon-only button's accessible name.
- copiedLabel= "Copied"
- string
- Label once copied.
- errorLabel= "Failed"
- string
- Label if the clipboard refuses.
- showLabel= false
- boolean
- Show the label beside the icon.
- timeoutMs= 2000
- number
- How long the copied state stays.
- variant= "ghost"
- "secondary" | "outline" | "ghost"
- Visual appearance.
- size= "sm"
- "xs" | "sm" | "md"
- 24, 28 or 36px tall.
- onCopySuccess / onCopyError
- (text) => void / (error) => void
- Called once the clipboard answers.
Accessibility and motion
- Uses navigator.clipboard, with a selection fallback for older browsers and plain-http pages.
- The copied state is optimistic: it shows on the press, not after the clipboard promise.
- Reduced motion: icons and labels change in place, no shake.
Requirements
React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.
The CLI also installs Text morph.
Source
Registry item: /r/copy-button.json


