React component for shadcn/ui
Copy Button
Copy text to the clipboard with visual, sound, and haptic feedback.
Copy Button is a React copy-to-clipboard button for shadcn/ui that confirms each copy with an animated icon, a UI sound, and a haptic tap. Use it next to code snippets, install commands, API keys, and share links.
Features
- Accepts text as a value or a function resolved when the button is clicked.
- Animates idle, success, and error icons before returning to idle.
- Plays matching UI sounds and haptics for successful and failed copies.
- Supports custom state icons and copy outcome callbacks.
Installation
pnpm dlx shadcn@latest add @tentui/copy-button
Usage
import { CopyButton } from "@/components/copy-button";<CopyButton size="default" variant="outline" text="npm install tentui">
Copy command
</CopyButton>Pass a function when the value should be resolved at click time.
<CopyButton text={() => window.location.href} aria-label="Copy page URL" />Accessibility
CopyButton preserves the underlying button's keyboard and focus behavior and
uses Copy as its default accessible label. Set aria-label to describe a more
specific action when needed.
Success and error feedback is visual. Announce the result separately when confirmation needs to be available to assistive technology.
API reference
FAQ
How do I install the Copy Button with shadcn?
Run npx shadcn@latest add @tentui/copy-button after adding the @tentui
registry to components.json (installation guide), or run
npx shadcn@latest add https://tentui.com/r/copy-button.json without it. The
CLI copies copy-button.tsx, its icon-swap helper, and the
use-copy-to-clipboard hook into your project, adds the shadcn button, and
installs motion, lucide-react, web-haptics, and @rexa-developer/tiks.
Can I copy a value that's only known at click time?
Yes. Pass a function to text, such as () => window.location.href, and it
runs on click; it can also return a promise. Async text is written through a
ClipboardItem promise so Safari still treats the copy as part of the click.
Why does the Copy Button show an error instead of copying?
Browsers only expose the Clipboard API in secure contexts, so copying fails on
plain HTTP pages other than localhost, and it also fails if a text function
throws. The button then shows the error icon and calls onCopyError with the
error.
Is the Copy Button accessible?
It is a native button with keyboard and focus behavior intact, and its default
accessible name is "Copy". Set aria-label when the button has its own visible
text or copies something specific, and announce the result yourself if
screen-reader users need it, because the success and error states are visual.
How do I change the icons and style?
Pass idleIcon, doneIcon, and errorIcon to replace the Lucide icons, and
any shadcn Button prop such as variant, size ("icon" by default), or
className. The icon returns to idle 1.5 seconds after each copy.
Is the Copy Button free to use?
Yes. The Copy Button is free and source-available: the shadcn CLI copies its source into your project, and you can use it in unlimited personal and client projects under the TentUI License. The license doesn't allow redistributing or reselling the component itself.
Related components
All buttons and toggles- Glass Toggle
An on/off switch with a thumb of thick frosted glass. Flip it and the thumb springs across, a pixel moon scatters and reassembles as a pixel sun, and a rim light runs round the glass from cool lilac to warm amber.
- Hold to Confirm
Guard destructive actions behind a press-and-hold fill with rising sound, haptic ticks, and a checkmark.
- Peeping Button
Add a shy, cursor-tracking surprise behind a familiar button face.
- Pull Cord
A ball-chain pull switch for a light. Drag the handle down and the chain feeds out bead by bead with a tick each, then flips with a click on release and swings back to rest.
Related guides
All guides- React Copy to Clipboard Button for shadcn/ui
Build a React copy-to-clipboard button for shadcn/ui with async text resolvers, Safari ClipboardItem support, error states, screen-reader feedback, and motion.
- Best Animated shadcn/ui Components in 2026
A guide to TentUI's animated shadcn/ui components by job, from async buttons and pickers to charts, overlays, text effects, and AI thinking UI.