Skip to content
animorio
IT
All components

Clear cart button

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

The «Clear cart» button at the bottom of a cart summary with three line-drawn products, a mug, a candle and a linen tote. You hold it so you never clear it by mistake: the pill fills with brick red from the left, the label widens on the width axis, the trash lid lifts and the rows shiver slightly. At the end the items fly out on an arc one after the other, the total and the item count roll to zero, and an Undo with a five-second ring springs them back into place.

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>
<!--
  "Clear cart 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>Clear cart button</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">
    <!-- a small cart summary with a Clear cart button you have to hold: the pill fills from the left, the trash lid
         lifts and the rows shiver; hold to the end and the items fly out, the totals roll to zero, Undo brings them back -->
    <section class="cart" data-cart aria-label="Shopping cart">
      <header class="cart__head">
        <span class="cart__title">Your cart</span>
        <span class="cart__count"><span class="roll" data-count><span class="roll__line">3 items</span></span></span>
      </header>

      <div class="cart__body" data-body>
        <ul class="cart__list" data-list>
          <li class="row" data-row>
            <span class="row__inner" data-row-inner>
              <span class="thumb" aria-hidden="true">
                <svg viewBox="0 0 40 40"><path d="M11 13h15v13a4 4 0 0 1-4 4h-7a4 4 0 0 1-4-4V13Z"/><path d="M26 16h2.5a3 3 0 0 1 0 6H26"/><path d="M15 9.5c0-1.4 1.6-1.4 1.6-2.8M19.5 9.5c0-1.4 1.6-1.4 1.6-2.8" class="thumb__soft"/></svg>
              </span>
              <span class="row__text"><span class="row__name">Stoneware mug</span><span class="row__var">Sand · Qty 1</span></span>
              <span class="row__price">$28.00</span>
            </span>
          </li>
          <li class="row" data-row>
            <span class="row__inner" data-row-inner>
              <span class="thumb" aria-hidden="true">
                <svg viewBox="0 0 40 40"><path d="M13 16h14v14H13z"/><path d="M13 20h14" class="thumb__soft"/><path d="M20 16v-3.5"/><path d="M20 12.5c-1.6-1.6-1.2-3.6 0-5.5 1.2 1.9 1.6 3.9 0 5.5Z" class="thumb__flame"/></svg>
              </span>
              <span class="row__text"><span class="row__name">Beeswax candle</span><span class="row__var">Fig leaf · Qty 1</span></span>
              <span class="row__price">$34.00</span>
            </span>
          </li>
          <li class="row" data-row>
            <span class="row__inner" data-row-inner>
              <span class="thumb" aria-hidden="true">
                <svg viewBox="0 0 40 40"><path d="M10.5 16h19l-1.6 15h-15.8L10.5 16Z"/><path d="M15.5 16v-2a4.5 4.5 0 0 1 9 0v2"/><path d="M14 21.5h12" class="thumb__soft"/></svg>
              </span>
              <span class="row__text"><span class="row__name">Linen tote</span><span class="row__var">Natural · Qty 1</span></span>
              <span class="row__price">$86.00</span>
            </span>
          </li>
        </ul>

        <div class="empty" data-empty aria-hidden="true">
          <svg class="empty__bag" viewBox="0 0 40 40"><path d="M9.5 15h21l-1.8 16.5H11.3L9.5 15Z"/><path d="M15 15v-2.2a5 5 0 0 1 10 0V15"/></svg>
          <span class="empty__title">Your cart is empty</span>
          <span class="empty__sub">Saved items stay in your wishlist.</span>
        </div>
      </div>

      <div class="cart__sum">
        <span>Subtotal</span>
        <span class="cart__total" data-total>$148.00</span>
      </div>

      <div class="pill-wrap">
        <button class="pill" type="button" data-pill data-autoclic aria-describedby="hint">
          <span class="pill__face" data-face>
            <span class="pill__fill" aria-hidden="true"></span>
            <span class="pill__label" data-label-base>
              <svg class="bin" viewBox="0 0 16 16" aria-hidden="true"><g data-lid><path d="M2.6 4.2h10.8M6.3 4.2V2.9h3.4v1.3"/></g><path d="M3.9 5.9 4.6 13.4h6.8l.7-7.5M6.7 7.6v3.9M9.3 7.6v3.9"/></svg>
              <span>Clear cart</span>
            </span>
            <span class="pill__label pill__label--on" aria-hidden="true">
              <svg class="bin" viewBox="0 0 16 16"><g data-lid-on><path d="M2.6 4.2h10.8M6.3 4.2V2.9h3.4v1.3"/></g><path d="M3.9 5.9 4.6 13.4h6.8l.7-7.5M6.7 7.6v3.9M9.3 7.6v3.9"/></svg>
              <span>Clear cart</span>
            </span>
            <span class="pill__done" data-done aria-hidden="true">
              <svg class="tick" viewBox="0 0 16 16"><path data-tick pathLength="1" d="M3.4 8.4 6.6 11.4 12.6 4.8"/></svg>
              <span>Cart cleared</span>
            </span>
          </span>
        </button>
      </div>

      <div class="cart__foot">
        <span class="hint" id="hint" data-hint>Hold to clear</span>
        <button class="undo" type="button" data-undo tabindex="-1">
          <svg class="undo__ring" viewBox="0 0 20 20" aria-hidden="true"><circle class="undo__track" cx="10" cy="10" r="7.5"/><circle class="undo__time" data-undo-time cx="10" cy="10" r="7.5" pathLength="1"/></svg>
          <span>Undo</span>
        </button>
      </div>
      <p class="sr" aria-live="polite" data-live></p>
    </section>
  </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.

37 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

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 “Clear cart 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 small cart summary, «Your cart · 3 items», with three rows: Stoneware mug, Beeswax candle and Linen tote, each with its line-drawn thumbnail, variant and price; below, the subtotal, $148.00, and the «Clear cart» pill with a trash can. Hold it and the pill fills from the left, the white label uncovers the red one, the trash lid opens and the rows shiver more and more. Let go early and it springs back. Hold to the end and it squashes and bounces, turns into «Cart cleared» with a tick drawing itself, the items fly out on an arc, the total drops to $0.00, the count becomes «0 items» and «Your cart is empty» appears in the middle. Undo slides in with a ring that runs down in five seconds: tap it and the items come back, last one first.

How it works

One variable

The fill is one CSS variable, --p, from 0 to 1: the red background is a scaleX(var(--p)) from the left, the white label is a copy of the red one clipped with clip-path, the label widens with font-stretch: calc(100% + var(--p) * 20%) and the pill’s shadow tightens with the same variable.

Holding

On press GSAP takes p to 1 in HOLD seconds with power1.in; the trash lid turns around its hinge with svgOrigin in the icon’s coordinates, and the rows shiver with two sines on the ticker, harder towards the end. Let go early and p goes back to 0 with elastic.out.

The flight

Each row flies with three overlapping tweens: x speeding up to the right, y with three keyframes (up, then down) for the arc, rotation and opacity; rows leave STAGGER seconds apart.

Undo

The Undo ring is a circle with pathLength 1 whose stroke-dashoffset goes from 0 to 1 in UNDO_TIME seconds. Undoing brings the rows back last to first with elastic.out while the total climbs back.

Values to change

NameFileDefaultWhat it changes
HOLDscript.js1.4Seconds of holding to fill the pill and clear the cart.
UNDO_TIMEscript.js5Seconds Undo stays available, shown by the ring around it.
FLYscript.js0.75Seconds each item takes to fly out of the cart.
STAGGERscript.js0.09Seconds between one item and the next.
LIDscript.js32Degrees the trash lid lifts while you hold.
SHIVERscript.js0.9Pixels the rows shiver at the end of the hold.
SPRINGscript.js0.45How springy the pill is when you let go early (lower = more bounce).

Try them in the Playground

When to use it

At the bottom of an online shop’s cart, in an order summary or in any list you can empty in one go (mail, downloads, notifications): an action that removes a lot and wants a stronger confirmation than a click, without a dialog.

On phones

Everything is in em and the size depends on both the width and the height of the window, so the cart fits the phone box. A finger holds like the mouse.

With reduced motion

No springs, flights or shivers: the pill fills and empties without bouncing, the lid stays still, the items fade out and back and the numbers change at once.

Pitfalls

  • The lid turns inside the svg: svgOrigin with the real hinge in viewBox coordinates (2.6 4.2), not transformOrigin.
  • The release spring takes p below zero: clamp it with Math.max(0, p), or a negative scaleX flips the fill.
  • Without setPointerCapture, sliding off the pill while holding would end the gesture; on touch you also need touch-action: none and to block the context menu.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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