Skip to content
animorio
IT
All components

Promo code field

Forms, HoverGSAP, CSS onlyMediumCompressed weight: Demo 8.0 KBGSAP 28 KBFreeDownload the zip

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.

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>
<!--
  "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>

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.

42 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 “Promo code field” 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 the palest grey sits the order summary of Oakmere, an invented clothing shop: a merino sweater and a waxed canvas tote with their prices, the «Promo code» field with a drawn voucher and the Apply button, and underneath subtotal, shipping and total, €184.00. As you type, the letters come in one at a time with a small hop and the caret blinks; as soon as the code has three characters Apply turns black. Pressed, it squashes slightly, its label rises away and a small loading circle spins in its place. If the code is wrong the field shakes, its border turns red and «This code isn’t valid or has expired» opens underneath; typing again closes the message. If it’s right the field folds into a dashed green chip, with the voucher, a tick that draws itself, the code and the saving, −€18.40, and a cross. In the summary the Discount line opens with the code in a green tag, then the digits of the total roll on their wheels, from right to left, to €165.60, and «You save €18.40» appears below. The cross takes the discount off: the chip goes, the field comes back empty, the line closes and the total rolls back up. A drawn pointer does it all by itself, getting the code wrong the first time; you can also really type, and Enter works as Apply.

How it works

The real field is invisible

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

Apply checking

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.

From field to chip

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.

The total on wheels

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.

Values to change

NameFileDefaultWhat it changes
BRANDscript.jsOakmereThe name of the invented shop, at the top of the card.
ACCENTscript.js#17804cThe colour of the right code, the chip and the discount.
CODEscript.jsWINTER10The promo code the field accepts.
PERCENTscript.js10The code’s discount, as a percentage of the subtotal.
TYPE_SPEEDscript.js10The letters per second the autopilot types.
ROLLscript.js0.9The seconds the digits of the total take to roll.
SPRINGscript.js1.6How much the chip bounces as it takes the field’s place.
PAUSEscript.js1.3The seconds the autopilot waits between one gesture and the next.

Try them in the Playground

When to use it

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.

On phones

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.

With reduced motion

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.

Pitfalls

  • With natural-width digits the total would change size with every number and jiggle on the right: each digit sits in a fixed-width window. In Mona Sans tabular figures draw a slashed zero, so windows are used instead of tabular-nums.
  • The light tints of the green, worked out with color-mix in the CSS, vanished in the preview video: the script computes them from the accent colour and writes them into the variables.
  • A chip as wide as its text must be measured before it is animated: it is made visible with width auto, offsetWidth is read, and only then does the spring start from the field’s width.

Libraries

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.

Testing

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