Skip to content
animorio
IT
All components

Copy code button

Buttons, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 6.9 KBGSAP 28 KBFreeDownload the zip

The code block of the docs of Kestrel, a made up payments API, on black: four coloured lines with the Node.js, Python and cURL tabs and the Copy pill in the top right. On hover the two sheets of the icon part by a pixel; on press the lines light up one after another as if they were being read, a ghost copy of the block lifts a few pixels and slides back into the pill, which turns into «Copied» with a tick that draws itself and after two seconds goes back to Copy with a settle. It really copies.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Copy code button" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>The Copy button of a code block with the lines read back into the pill</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage" data-stage>
    <!-- the code block of an API reference: pressing Copy reads the lines one by one,
         a ghost copy of the block lifts off and slides back into the pill, which turns into Copied -->
    <figure class="code" data-code>
      <div class="code__bar">
        <div class="tabs" aria-label="Language">
          <span class="tab is-on">Node.js</span>
          <span class="tab">Python</span>
          <span class="tab">cURL</span>
        </div>
        <button class="copy" type="button" data-copy data-autoclic aria-label="Copy code">
          <span class="copy__light" aria-hidden="true"></span>
          <svg class="copy__icon" viewBox="0 0 16 16" aria-hidden="true">
            <g class="sheets" data-sheets>
              <rect class="sheet sheet--back" data-back x="5.6" y="1.6" width="8.4" height="9.6" rx="2.2"/>
              <rect class="sheet sheet--front" data-front x="2" y="4.8" width="8.4" height="9.6" rx="2.2"/>
            </g>
            <path class="tick" data-tick d="M3.4 8.6 6.5 11.6 12.8 4.6"/>
          </svg>
          <span class="copy__words" data-words>
            <span class="copy__label" data-l-copy>Copy</span>
            <span class="copy__label copy__label--done" data-l-done aria-hidden="true">Copied</span>
          </span>
        </button>
      </div>
      <pre class="code__body" data-body><code><span class="ln" data-line><span class="ln__glow"></span><span class="ln__n">1</span><span class="ln__t"><span class="t-k">import</span> <span class="t-v">Kestrel</span> <span class="t-k">from</span> <span class="t-s">"kestrel"</span><span class="t-p">;</span></span></span>
<span class="ln" data-line><span class="ln__glow"></span><span class="ln__n">2</span><span class="ln__t"><span class="t-k">const</span> <span class="t-v">k</span> <span class="t-p">=</span> <span class="t-k">new</span> <span class="t-f">Kestrel</span><span class="t-p">(</span><span class="t-c">API_KEY</span><span class="t-p">);</span></span></span>
<span class="ln" data-line><span class="ln__glow"></span><span class="ln__n">3</span><span class="ln__t"><span class="t-k">await</span> <span class="t-v">k</span><span class="t-p">.</span><span class="t-v">payments</span><span class="t-p">.</span><span class="t-f">create</span><span class="t-p">({</span></span></span>
<span class="ln" data-line><span class="ln__glow"></span><span class="ln__n">4</span><span class="ln__t">  <span class="t-a">amount</span><span class="t-p">:</span> <span class="t-n">2400</span><span class="t-p">,</span> <span class="t-a">currency</span><span class="t-p">:</span> <span class="t-s">"eur"</span> <span class="t-p">});</span></span></span></code></pre>
      <div class="ghostcopy" data-ghostcopy aria-hidden="true"><div class="ghostcopy__in" data-ghostin></div></div>
    </figure>
    <p class="sr" data-live aria-live="polite"></p>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

53 values to change

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Copy code button” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

A graphite code block with a thread of light on its top edge: above, the Node.js, Python and cURL tabs; below, four numbered lines that create a payment with Kestrel, with keywords in lavender, strings and numbers in sand, properties in light blue and dim punctuation. In the top right the 28 pixel Copy pill with the two sheets icon. On hover (or with the Tab key) the back sheet rises a pixel and the front one drops half, a light follows the pointer and «Copy» widens on the wdth axis; pressed, the pill sinks. On click a mint light runs along each line, one after another, the number lights up and the text takes a one pixel step and settles, as if the code were being read. Then a ghost copy of the block, made of glass with a mint edge, lifts six pixels with a small bounce and speeds into the pill, shrinking down to its shape. The pill gives a beat, the sheets fold away and the tick draws itself, the label rolls to «Copied» and the pill widens on a spring. Two seconds later (or with another click) it goes back to Copy: it narrows, goes a pixel too far and settles, and the sheets come back with a bounce.

How it works

A real block, written by hand

The code is a pre with one span per line, the numbers and syntax colours in classes. The container is a flex column: so the line breaks between the lines, which would count inside a pre, disappear. The text to copy is read from the lines and goes to the clipboard with navigator.clipboard.writeText.

The lines being read

Every line has a layer of light that grows with scaleX from the left, with a mint thread on its edge; they start READ seconds apart, the number takes the accent and the text takes a one pixel step that comes back with elastic.out.

The ghost copy

At start the code is cloned inside a glass with backdrop-filter. On press the glass takes the exact place of the code, lifts LIFT pixels with back.out and then animates left, top, width, height and the radius down to the pill: not a scale, which would squash the corners, but the real size, with power3.in speeding towards the end.

The pill that changes word

Copy and Copied sit one over the other in a 16 pixel window and roll with yPercent and font-stretch; the width of the window is measured from the two words and goes from one to the other with elastic.out, so the pill widens and narrows with a one pixel settle. The tick draws itself with stroke-dashoffset and on the way back leaves from the other end.

States and pilot

Rest, hover and focus with the sheets parting, pressed, copy in progress, done with an aria-live announcement and a changed label, back by itself or with a click. A drawn pointer comes in, rests, clicks and waits for the whole round; at the first real touch it stops and starts again after six quiet seconds.

Values to change

NameFileDefaultWhat it changes
READscript.js0.12Seconds between one line being read and the next.
LIFTscript.js6How many pixels the ghost copy of the block lifts.
FLYscript.js0.55Seconds for the copy to go back into the pill.
HOLDscript.js2Seconds «Copied» stays before going back to Copy.
SPLITscript.js1How many pixels the two sheets of the icon part on hover.
PRESS_SCALEscript.js0.94How far the pressed pill sinks.
ACCENTscript.js#7ff0c4The accent colour: the light on the lines, the tick and Copied.

Try them in the Playground

When to use it

In API docs, a library README, a programming blog or the install page of a developer product: any code block meant to be copied. With working tabs it becomes the multi language block of the guides.

On phones

The same animation: the block is at most the screen width minus 32 pixels and the code shrinks with clamp down to 10.4 pixels, so the longest line always fits. A tap is hover and click together.

With reduced motion

Nothing moves: the lines light up all together with a fade, the ghost copy appears and fades in place without flying, labels and icon swap with a fade; the pilot’s pointer is hidden.

Pitfalls

  • The line breaks between the lines inside the pre made an extra empty line between each: with the code as a flex column, the bare whitespace between the spans no longer counts.
  • With a scale the ghost copy reached the pill with its corners squashed into ovals: the real size and radius are animated instead, which costs little on such a small element.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 6.9 KB; the libraries: GSAP 28 KB.

Testing

Tested on 11 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All components