
The elastic button
Buttons, Hover, Text
The promo code field in an order summary, on the palest grey: you type the code and the letters hop in, Apply spins while it checks, a wrong code shakes the field with the message underneath, the right one folds into a green chip with its saving, the Discount line opens in the summary and the digits of the total roll on their wheels to the new price. The chip’s cross takes the discount off and the total rolls back up.
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>
<!--
"Promo code field" 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 promo code field that recalculates the total</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>
<!-- the order summary of a shop: type a promo code, Apply checks it, the code turns into a chip with its saving, the
Discount line opens in the summary and the total rolls down to its new value; a wrong code shakes the field -->
<section class="sum" data-card aria-label="Order summary">
<header class="sum__head">
<p class="sum__brand"><span data-brand>Oakmere</span> <span class="sum__crumb">/ Checkout</span></p>
<p class="sum__title">Order summary</p>
</header>
<ul class="items">
<li class="item">
<span class="item__pic item__pic--a" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M8 4h8l3 4-3 2v10H8V10L5 8z"></path></svg></span>
<span class="item__txt"><span class="item__name">Merino crew sweater</span><span class="item__meta">Oat · M</span></span>
<span class="item__price">€129.00</span>
</li>
<li class="item">
<span class="item__pic item__pic--b" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M5 9h14l-1 11H6z"></path><path d="M9 9V7a3 3 0 0 1 6 0v2"></path></svg></span>
<span class="item__txt"><span class="item__name">Waxed canvas tote</span><span class="item__meta">Olive</span></span>
<span class="item__price">€55.00</span>
</li>
</ul>
<div class="promo" data-promo>
<div class="field" data-field>
<svg class="field__icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V6h16v3a3 3 0 0 0 0 6v3H4v-3a3 3 0 0 0 0-6z"></path><path d="M14 6v2.5M14 11v2M14 15.5V18"></path></svg>
<span class="field__text" data-text aria-hidden="true"><span class="field__ph" data-ph>Promo code</span><span class="field__typed" data-typed></span><span class="caret" data-caret></span></span>
<input class="field__input" type="text" autocomplete="off" autocapitalize="characters" spellcheck="false" maxlength="16" aria-label="Promo code" aria-describedby="promo-status" data-input>
<button class="apply" type="button" data-apply>
<span class="apply__label" data-apply-label>Apply</span>
<svg class="apply__spin" viewBox="0 0 24 24" aria-hidden="true" data-spin><circle cx="12" cy="12" r="8"></circle><path d="M12 4a8 8 0 0 1 8 8"></path></svg>
</button>
</div>
<div class="chip" data-chip aria-hidden="true">
<svg class="chip__icon" viewBox="0 0 24 24"><path d="M4 9V6h16v3a3 3 0 0 0 0 6v3H4v-3a3 3 0 0 0 0-6z"></path><path d="M9 12.2l2 2 4-4.2" data-chip-tick></path></svg>
<span class="chip__code" data-chip-code>WINTER10</span>
<span class="chip__save" data-chip-save>−€18.40</span>
<button class="chip__x" type="button" aria-label="Remove code" data-remove><svg viewBox="0 0 24 24"><path d="M7 7l10 10M17 7L7 17"></path></svg></button>
</div>
<p class="error" data-error aria-hidden="true">
<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5"></circle><path d="M12 8v4.5M12 15.6v.01"></path></svg>
<span>This code isn’t valid or has expired</span>
</p>
</div>
<p class="sr" id="promo-status" aria-live="polite" data-status></p>
<dl class="lines">
<div class="line"><dt>Subtotal</dt><dd>€184.00</dd></div>
<div class="line"><dt>Shipping</dt><dd>Free</dd></div>
<div class="line line--disc" data-disc>
<div class="line__in" data-disc-in><dt>Discount <span class="line__code" data-disc-code>WINTER10</span></dt><dd class="line__neg" data-disc-amt>−€18.40</dd></div>
</div>
<div class="line line--total"><dt>Total</dt><dd class="total" data-total aria-live="polite"></dd></div>
</dl>
<p class="saved" data-saved aria-hidden="true">You save <span data-saved-amt>€18.40</span></p>
</section>
<svg class="pointer" viewBox="0 0 24 24" aria-hidden="true" data-pointer><path d="M5 3l14 8.2-6.2 1.4 3.6 6.8-2.6 1.4-3.6-6.8L5 18.6z"></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>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.
42 values to change
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 “Promo code field” from Animorio and fit it into my siteAbove the drawing lies a real input at zero opacity, which receives the keyboard and touch. What you see is one span per character: on each input the new value is compared with the old one and only the characters that changed are added or removed, so letters already typed never hop again.
On click the label rises away and an SVG circle spins 540 degrees in just over a second; then the code is compared with the right one. A wrong code opens the error message by taking its height from zero and shakes the field with a six-step keyframe that dies down.
The chip sits in the same place as the field, hidden. Its natural width is measured, then it starts as wide as the field and shrinks to its own size on a back.out spring while the field fades underneath; inside, icon, code, saving and cross come in one after another and the tick draws itself with its dash.
Every digit of the total is a column of ten numbers inside a window one line tall and always the same width. To change the price each column moves by the yPercent of its new digit, starting from the last one on the right, 0.06 seconds apart, with a small overshoot.
| Name | File | Default | What it changes |
|---|---|---|---|
BRAND | script.js | Oakmere | The name of the invented shop, at the top of the card. |
ACCENT | script.js | #17804c | The colour of the right code, the chip and the discount. |
CODE | script.js | WINTER10 | The promo code the field accepts. |
PERCENT | script.js | 10 | The code’s discount, as a percentage of the subtotal. |
TYPE_SPEED | script.js | 10 | The letters per second the autopilot types. |
ROLL | script.js | 0.9 | The seconds the digits of the total take to roll. |
SPRING | script.js | 1.6 | How much the chip bounces as it takes the field’s place. |
PAUSE | script.js | 1.3 | The seconds the autopilot waits between one gesture and the next. |
For the cart or checkout of an online shop, a subscription payment, an event booking: anywhere a promo code can be typed and it pays to show right away how much is saved.
The card takes the full width minus the margins, its inner spacing tightens with vmin, and the real input underneath uses 16-pixel text, so Safari doesn’t zoom the page when it’s tapped. A tap opens the real keyboard.
No hops, no shaking and no rolling digits: the code is already applied, with the chip, the Discount line open and the total at €165.60; the drawn pointer stays hidden.
GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.
Compressed with gzip, the three demo files weigh 8.0 KB; the libraries: GSAP 28 KB.
Tested on 28 October 2026
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.
Support Animorio
Animorio stays free thanks to the people who support it. If you like, buy us a coffee: it helps us make the next animations.
You asked for
We made it for you: it’s in the library, with the preview, the Playground and the code to copy.
An animation you can’t find, or a site to take apart in the journal: tell us which. We pick the next ones from here.
With your account’s email and password.
or with your email
You’re signed in as .
With your account, you can download the zip of every animation and every pack, for free.