Skip to content
animorio
IT
All components

Attach button

Buttons, Hover, SVGGSAP, CSS onlyEasyCompressed weight: Demo 4.8 KBGSAP 28 KBFreeDownload the zip

One button, one line: the white «Attach» pill with a paperclip drawn as a thin line; on tap the clip retracts along its own line, draws itself again in the accent colour astride the top edge, its long leg passing behind the pill, and the label becomes «Attached» with the file name in grey. On a second tap it comes off and turns back into an icon.

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>
<!--
  "Attach 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 Attach button with the paperclip that clips onto 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="style.css">
</head>
<body>
  <main class="stage" data-stage>
    <!-- one button, one line: the paperclip draws itself and clips onto the top edge of the pill -->
    <button class="attach" type="button" data-attach aria-pressed="false" aria-label="Attach">
      <!-- the leg that goes behind the pill: drawn under it, so the edge hides it -->
      <svg class="attach__clip attach__clip--back" viewBox="0 0 24 48" aria-hidden="true" data-clip>
        <path class="attach__line" data-back d="M20 10V36a8 8 0 0 1-16 0V16"/>
      </svg>
      <span class="attach__body" data-body>
        <span class="attach__slot" aria-hidden="true"></span>
        <span class="attach__label" aria-hidden="true">
          <span class="attach__word" data-word="on">Attach</span>
          <span class="attach__word" data-word="off"><span data-done>Attached</span><span class="attach__file" data-file>report.pdf</span></span>
        </span>
      </span>
      <!-- the part in front of the pill -->
      <svg class="attach__clip attach__clip--front" viewBox="0 0 24 48" aria-hidden="true" data-clip>
        <path class="attach__line" data-front d="M16 14V34a4 4 0 0 1-8 0V10a6 6 0 0 1 12 0"/>
      </svg>
    </button>
  </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.

16 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 “Attach 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

On white, alone in the middle, there is a white pill with a thin border, a paperclip drawn with a single line and the word «Attach». On tap the pill gives a little and comes back on a spring; the clip retracts along its own line, the long leg first, and disappears. Right after it draws itself again higher up, in the accent colour and slightly tilted, astride the edge of the pill: the front part first, then the long leg, which passes behind the pill and only shows above the edge, so the clip really closes on the border. It lands a pixel low and settles, and the edge gives by half a pixel as if bitten. Meanwhile «Attach» rises away and «Attached» comes in narrow and opens up on the width axis, with the file name in grey after a thin rule; the pill stretches on a spring as much as it needs. On a second tap the clip lifts off the edge, erases from the far end and draws itself back inside the pill as an icon, and «Attach» returns. Hovering brings the pill a touch closer and tilts the clip towards the word. Until someone touches it, the button plays the gesture by itself.

How it works

One line in two pieces

The clip is a single stroke split across two SVGs with the same size and position: the front part sits above the pill, the long leg below it. The pill’s white fill hides the leg under the edge: no masks, the stacking order is what closes the clip.

Retracted and redrawn

Both lines have a strokeDasharray equal to their length: to retract, the strokeDashoffset goes to the length, to redraw it comes back to zero, the front part first and then the leg. The move onto the edge happens while the line is not there, so it is never seen sliding.

The bite on the edge

The clip lands a pixel below its place and comes back up on an elastic spring; at the same moment the pill drops by 0.6 pixels and returns: it is the edge taking the clip.

The word coming in narrow

The old word leaves before the new one arrives, which comes up from below with the wdth axis at 75 and lands at 100 with back.out: the two are never read together. The pill takes the width of the new word, measured in its final shape.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#3657ffThe colour of the clip once attached.
LABEL_ONscript.jsAttachThe word before.
LABEL_OFFscript.jsAttachedThe word after.
FILE_NAMEscript.jsreport.pdfThe file name beside the word.
TILTscript.js-8How many degrees the clip leans on the edge.
SPRINGscript.js1How springy the press and the landing are: 0.4 calm, 2 very bouncy.
SPEEDscript.js1The speed of everything: 2 twice as fast, 0.5 half.
HOLDscript.js2.4How many seconds each state stays when the button plays by itself.
AUTOscript.jstrueThe button plays the gesture by itself until someone touches it.

Try them in the Playground

When to use it

For the button that attaches a file in an email, a chat or a form: the clip on the edge says by itself that the file is attached, and the name beside it says which.

On phones

On the phone the pill and the clip take their size from the screen (clamp on the shorter side); there is no hover, everything else is the same.

With reduced motion

The clip and the words swap with a fade, with no springs or movement; the pill takes its new width at once.

Pitfalls

  • While the clip is an icon inside the pill, the long leg must show too: its SVG goes above the pill and back under only while the line is retracted, otherwise it would be seen vanishing at once.
  • The position on the edge depends on the pill’s height, which changes with the clamp: it is recalculated on every tap and on resize, using the CSS height and not the bounding box, which is taller once tilted.
  • The new word’s width has to be measured in its final shape, before it comes in narrow, and divided by the press scale.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 30 October 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