Skip to content
VenusUI
Get started

Copy Button

Copies text to the clipboard and confirms with a check mark and a screen reader message.

Preview

Installation

npx shadcn@latest add @venusui/copy-button

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/copy-button.tsx

Usage

The code behind the preview above.

copy-button-demo.tsx

import { CopyButton } from "@/components/ui/copy-button"

export default function CopyButtonDemo() {
  return (
    <div className="flex items-center gap-3">
      <code className="rounded-md border bg-muted/50 px-3 py-1.5 font-mono text-sm">npm install motion</code>
      <CopyButton value="npm install motion" aria-label="Copy install command" />
      <CopyButton value="npm install motion">Copy</CopyButton>
    </div>
  )
}

API reference

PropTypeDefaultDescription
valuestring—Text to copy. Required.
timeoutnumber2000Milliseconds the copied state is shown.
onCopy(value: string) => void—Called after a successful copy.

All <button> props except value. Give icon-only buttons an aria-label.

Requirements

  • lucide-react for icons, React 19 and Tailwind CSS v4.
  • A secure context (HTTPS or localhost) for the Clipboard API.

Customization

  • Pass children for a text button (<CopyButton value={x}>Copy</CopyButton>), or none for an icon button.
  • Style the copied state with data-[state=copied]: classes, e.g. a green border.

Accessibility

  • The result (“Copied” or “Copy failed”) is announced through a polite live region.
  • Icon-only usage needs aria-label, e.g. “Copy install command”.

Troubleshooting

Nothing is copied on a plain HTTP page.
Browsers only allow the Clipboard API on HTTPS and localhost. The button shows the failed state in that case.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

A heart toggle that pops and bursts when liked, with an optional count.

Loading preview

Pull-Cord Lamp

Interactive

A hanging lamp you switch by pulling its cord; it can toggle the page between light and dark mode.

Loading preview

Cards arranged in a ring that turns in 3D, with buttons, arrow keys and announcements.