Skip to content
animorio
IT
All components

Add to playlist button

Buttons, HoverGSAP, CSS onlyMediumCompressed weight: Demo 9.0 KBGSAP 28 KBFreeDownload the zip

The Add to playlist button of a music app, on black. Pressed, the pill widens and shows the playlist’s stack of covers, three already piled up and fanned out; the song’s cover lifts off its row, arcs over and drops on top of the stack, which squashes and settles on a spring, the 23 songs count rolls to 24 songs and the button says Added to Night Drive with a drawn check. A second tap takes the song out and the cover flies back to its row.

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>
<!--
  "Add to playlist 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 Add to playlist button with the cover that drops onto the stack</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">
    <!-- the Add to playlist button of a made-up music app: pressed, the pill widens and shows the playlist's stack of
         covers, the song's cover lifts off its row, arcs over and drops on the stack, the stack squashes and settles,
         the count rolls and the button says Added to Night Drive with a drawn check; a second press takes it out -->
    <div class="wrap" data-wrap>

      <!-- the song: its cover sits in a soft socket that shows when the cover leaves -->
      <div class="track" data-track>
        <span class="socket" data-socket>
          <span class="socket__ghost art art--harbour" aria-hidden="true"></span>
          <span class="cover" data-cover>
            <span class="cover__face art art--harbour" aria-hidden="true"></span>
            <span class="cover__sheen" data-sheen aria-hidden="true"></span>
          </span>
        </span>
        <span class="track__text">
          <b data-title>Glass Harbour</b>
          <i data-artist>Mira Vane · 3:41</i>
        </span>
        <svg class="track__wave" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 10v4M9 7v10M13 9v6M17 6v12M21 10v4"></path></svg>
      </div>

      <div class="pill" data-pill>
        <div class="pill__clip">
          <span class="pill__grain" aria-hidden="true"></span>
          <span class="pill__light" data-light aria-hidden="true"></span>

          <button class="add" type="button" data-add data-autoclic aria-pressed="false">
            <span class="closed" data-closed>
              <svg class="plus" data-plus viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5.5v13M5.5 12h13"></path></svg>
              <span class="closed__word" data-label>Add to playlist</span>
            </span>

            <span class="open" data-open aria-hidden="true">
              <span class="stack" data-stack>
                <span class="sc sc--1" data-sc><span class="art art--tide"></span></span>
                <span class="sc sc--2" data-sc><span class="art art--ember"></span></span>
                <span class="sc sc--3" data-sc><span class="art art--bloom"></span></span>
                <span class="sc sc--top" data-sctop><span class="art art--harbour"></span></span>
              </span>
              <span class="lines">
                <span class="line1">
                  <svg class="check" data-checkic viewBox="0 0 24 24"><path data-check d="M5.5 12.6 10 17 18.5 7.6"></path></svg>
                  <span class="roll" data-roll>
                    <span class="roll__item" data-r1>Night Drive</span>
                    <span class="roll__item" data-r2>Added to Night Drive</span>
                  </span>
                </span>
                <span class="line2"><span class="num" data-num></span><span class="unit" data-unit>songs</span></span>
              </span>
            </span>
          </button>
        </div>
        <span class="pill__edge" aria-hidden="true"></span>
      </div>

      <!-- the cover in flight: it lives in the wrap, above the row and the pill -->
      <span class="flyer" data-flyer aria-hidden="true"><span class="art art--harbour"></span><span class="flyer__sheen"></span></span>
      <p class="sr" data-live aria-live="polite"></p>
    </div>

    <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.

24 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 “Add to playlist 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 a black background there are the row of a song in a made-up music app, Ondra: the cover (a sun cut by the horizon over a striped sea, all made of gradients), Glass Harbour by Mira Vane with its length, and below it the graphite Add to playlist pill with its plus. As the pointer comes near, the cover tilts slightly toward it and a highlight runs over it; over the pill the plus turns a quarter and the pill rises a pixel, and pressed it gives a pixel. On click the pill widens on a spring, the plus spins away and three covers of the Night Drive playlist fan in, with its name and 23 songs. The song’s cover lifts, leaves its dark empty socket in the row, rises in an arc, shrinks and turns, and drops on top of the stack: the stack squashes down and springs back up, the covers under it sink two pixels one after the other, the pill gulps and an amber light crosses it. The 3 of 23 rolls to 4, Night Drive slides away and Added to Night Drive arrives, with the amber check drawing itself. A second tap does the opposite: the top cover lifts, arcs back into its socket and settles, the count goes back to 23 and the pill closes on Add to playlist. Left alone, a drawn pointer passes near the cover, presses, waits and presses again, and starts over.

How it works

One pill, two contents

Inside the pill a layer with overflow hidden holds the closed content (the plus and Add to playlist) and the open one (the stack and the two lines), both absolutely positioned from the left. Both widths are measured on the real words and GSAP only changes the pill’s width: elastic.out to open, back.out to close, and the open content is uncovered from the left.

Covers made only of gradients

Each cover is a class with three or four layered gradients (the sun is a radial-gradient cut by the background size, the sea a repeating-linear-gradient). So the flying copy is just another element with the same class, with no images and no duplicate ids.

The flight on a curve

A tween takes t from 0 to 1 and on every frame the flying cover is placed on a quadratic curve between its socket in the row and the spot on top of the stack, with the control point ARC pixels above the higher of the two. Both positions are read again on every frame with getBoundingClientRect, so the flight stays right even while the pill is still widening or the window is resized. Meanwhile the scale goes from 48 to 30 pixels and the rotation makes a half turn.

The stack that squashes

On landing the copy disappears and the real cover shows on top of the stack. The stack takes scaleY SQUASH with its origin at the bottom in 80 ms and comes back with elastic.out; the covers below sink two pixels in a cascade from the top, the pill scales to 1.018 and an amber radial light crosses it.

The count in digits

The number is one digit per cell, each a grid with overflow hidden: only the digits that change roll, the new one comes in from below with back.out and the old one leaves at the top. Taking the song out rolls them the other way.

The tilt toward the pointer

Two quickTo calls move the cover’s rotationX and rotationY toward the pointer (up to TILT degrees, inside a socket with perspective) and a soft-light radial highlight moves the same way. The drawn pointer of the autopilot does the same: on every frame it passes its position to the same function.

Values to change

NameFileDefaultWhat it changes
LABELscript.jsAdd to playlistThe label of the closed button.
PLAYLISTscript.jsNight DriveThe playlist’s name, written after Added to.
COUNTscript.js23How many songs the playlist has before adding.
ACCENTscript.js#ffb04aThe colour of the check, the count and the light.
FLIGHTscript.js0.8How many seconds the cover’s flight lasts.
ARCscript.js56How many pixels the cover rises above its row before dropping.
SQUASHscript.js0.84How much the stack squashes when the cover lands on it (1 = not at all).
TILTscript.js9How many degrees the cover tilts toward the pointer.
HOLDscript.js2.2How many seconds the song stays added in the autopilot before it is taken out.

Try them in the Playground

When to use it

In music, podcast or audiobook apps and sites, to add a song to a collection; it also works to save a product to a list or a photo to an album, where the stack shows where the thing went.

On phones

On the phone the gesture is the same with touch; the tilt toward the pointer is there only with a mouse. The row and the pill narrow with the screen and the flight is computed again on the real positions.

With reduced motion

With reduced motion nothing flies, tilts or rolls: the cover fades out of the row and fades in on top of the stack, the pill changes size while its content is hidden and the words change with a fade.

Pitfalls

  • A copy of the cover made with an SVG image would have had duplicate gradient ids, and the second copy stayed black: the covers are made only of CSS gradients, so the copy is just a class.
  • Computing the end of the flight only once, the cover landed to the left of the stack, because the pill was still widening on its spring and its centre was moving: start and end are read again on every frame.
  • A quickTo on a custom property writes numbers without units and the highlight’s gradient was no longer valid: the highlight reads a separate object and repaints the background only when it changes.
  • The check before the words, hidden with opacity, already took its room and Night Drive sat away from the edge: its width goes from 0 to 16 pixels together with the stroke drawing itself, and the open pill is measured with the check already wide.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 13 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