Copies a value to the clipboard. The copy icon charges, morphs into a drawn check and the result is announced; for secrets it wipes the clipboard after a countdown ring.
Use it next to anything people copy rather than read: commands, keys, links, hex values. It confirms the copy on the button itself, so no toast is needed.
When not to use
For a long form action that needs a pending and success flow use Action Button.
Use it next to anything people copy rather than read: install commands, API keys, hex colors,
invite links, code blocks. It confirms the copy where the eye already is, so no toast is needed.
For secrets (API keys, recovery codes, one-time passwords), clearAfter wipes the clipboard
after a countdown, so a key never lingers until the next paste.
For a long form action that needs a pending state, use Stateful Button instead.
The motion follows the MotionKit grammar in three beats. Pressing charges it: the button
sinks onto its shadow in 90ms and the icon squashes. The action happens on release: the copy
icon folds away with a twist and a check draws itself in on the temperament's spring. The
settle is a single success ring that leaves the button (a quarter of its size at lively)
and fades. Errors never bounce: the warning
icon arrives on the calm spring.
Icon-only by default; showLabel shows the label next to the icon and swaps it for
copiedLabel or errorLabel. Every label is laid out invisibly, so the button keeps one width
in every state.
A function that takes longer than 150ms shows a spinner and loadingLabel ("Copying"), sets
aria-busy and ignores further clicks until it settles. Faster ones never flash a spinner.
Call event.preventDefault() in onClick to cancel the copy.
clearAfter (seconds) empties the clipboard after a copy. Once the check has shown, the copy
icon comes back inside a success ring that drains one second per tick, and the label counts down
("Clears in 28s", from clearingLabel). When the time is up the clipboard is wiped and
"Clipboard cleared" (clearedLabel) is announced.
It never erases something else: copying again (from any MotionKit copy button, or Ctrl+C / Cmd+C
on the page) cancels the pending wipe. Browsers refuse clipboard writes from a page without
focus, so if the time runs out while the person is in another app, the wipe happens as soon as
the page gets focus back. The wipe still happens if the button unmounts (a closed dialog keeps
its promise). Copies made in other apps cannot be detected; that is the same trade-off password
managers make.
The default demo: the secret key is masked, fetched on copy (the spinner) and wiped from the
clipboard after 30 seconds; the publishable key copies plainly. Rotate swaps the key.
A native <button type="button"> named by label (default "Copy"), with a visible focus ring
and a 28px minimum target at the small size.
The outcome is announced through a polite role="status" region rendered next to the button
(not inside it, where some screen readers skip it under an aria-label): "Copied", or
errorLabel when the clipboard refuses the write or the value function rejects. A copy
announces the number of characters ("Copied, 32 characters"), and with clearAfter when the
clipboard clears, so a screen reader user knows what landed without hearing a secret read out.
Pass announceCopied to change the wording. With VoiceOver and Safari, activating the button
reads its name, then the announcement. The visible label swap, the icons and the countdown
ring are aria-hidden, so the button's name stays the action.
While a function value resolves, the button has aria-busy="true". The wipe is announced
once, when it happens; the per-second countdown is visible only, never announced.
When several rows each have a visible "Copy", pass aria-label (for example "Copy accent hex")
so every button names what it copies.
Copied and error states change the icon shape as well as the color (check, warning circle),
so the result never relies on color alone. Success and destructive colors pass AA on the
tinted surfaces in both themes.
Without a secure context (plain http on a LAN), or when the Clipboard API refuses the write
(an iframe without the clipboard permission), it falls back to a hidden, selected textarea and
gives focus back to the button. Only if both fail does it show the error.
Copying twice in a row announces again.
data-state is idle, loading, copied, clearing or error, for your own styling.
With reduced motion (the OS setting or MotionKitProvider reducedMotion="always") there is no
sink, squash, twist or halo: the copy icon cross-fades to the check in 120ms, the label swaps the
same way and the status is still announced. The spinner arc stays still, and the countdown ring
steps once per second instead of draining continuously.
During a clearAfter countdown one 1s interval updates the label
and the ring; it stops when the wipe happens or is cancelled.
Nothing runs while idle. The press is a transform on the button; the icon swap animates
transform, opacity and the check's stroke length; the ring is one transform and
opacity tween.
The success color comes from the --success token, which the CLI adds to your theme.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 6.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
class-variance-authority
motion · peer
Triggers
click, press
Reduced motion
No sink, squash, twist or halo: the copy icon cross-fades to the check in 120ms, the spinner arc stays still, the wipe countdown ring steps once per second, and the status is still announced.
Keyboard
Tab
Moves focus to the button
Space / Enter
Copies the value (the button sinks while the key is down)
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)