Skip to content
animorio
IT
All components

Redeem code button

Buttons, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 7.4 KBGSAP 28 KBFreeDownload the zip

Someone searched for “redeem code” and the library had cashback and points, but not the gesture of typing a code. A shop’s Redeem code button, black on white, with a drawn ticket: on click the pill widens on a spring into eight boxes, four and four with a dash in between, where the characters drop in one at a time with a small bounce and the current box lights up in violet. Apply checks it: a wrong code shakes the pill and flashes the boxes red for a moment; the right one gathers the characters towards the centre, the pill tightens into “+$25 credit” as the tick draws itself, and below the store credit rolls digit by digit from $15.00 to $40.00.

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>
<!--
  "Redeem code 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>Redeem code button</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- the Redeem code button of a made-up shop: the pill opens into eight boxes, the code goes in one character at a
         time, Apply checks it; a wrong code shakes, a good one folds into +$25 credit and the store credit rolls -->
    <div class="wrap" data-wrap>
      <div class="pill" data-pill>
        <div class="pill__lift" data-lift>
          <span class="pill__bg" data-bg></span>
          <span class="pill__sheen" aria-hidden="true"></span>

          <button class="face face--idle" type="button" data-face="idle" aria-label="Redeem code">
            <span class="ticket" data-ticket aria-hidden="true">
              <svg viewBox="0 0 24 24"><path class="ticket__body" d="M3.5 7.5h17v3a1.6 1.6 0 0 0 0 3.2v3h-17v-3a1.6 1.6 0 0 0 0-3.2z"></path><path class="ticket__cut" d="M14.5 8v8.4"></path></svg>
            </span>
            <span class="face__label">Redeem code</span>
          </button>

          <div class="face face--field" data-face="field" aria-hidden="true">
            <div class="slots" data-slots>
              <input class="slots__input" data-input type="text" inputmode="text" autocomplete="off" autocapitalize="characters" spellcheck="false" maxlength="12" aria-label="Gift card or promo code, 8 characters" tabindex="-1">
            </div>
            <button class="apply" type="button" data-apply tabindex="-1">Apply</button>
          </div>

          <button class="face face--done" type="button" data-face="done" aria-hidden="true" tabindex="-1">
            <svg class="tick" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.6l4.3 4.2L19 7.2" pathLength="1" data-tick></path></svg>
            <span class="face__label" data-done-label>+$25 credit</span>
          </button>
        </div>
      </div>

      <p class="note" aria-live="polite"><span class="note__line" data-note>Have a gift card or promo code?</span></p>
      <p class="credit"><span class="credit__label">Store credit</span><span class="money" data-money aria-live="polite"></span></p>
    </div>
  </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.

20 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 “Redeem code 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

In the middle of a white page sits a 60 pixel black pill with a ticket drawn in white line and “Redeem code”; below, in grey, “Have a gift card or promo code?” and the small light pill of the store credit, $15.00. On hover the pill rises one pixel and lightens slightly, and the ticket tilts with a bounce. On click the pill squashes and springs back, then widens on a spring to the size of the field: eight dark boxes, four and four with a dash in between, and next to them Apply, white but dimmed until the code is complete. The current box has a violet ring and a thin breathing caret; each character comes up from below, grows with a bounce and dips its box by a pixel and a half. Apply with a wrong code shakes the pill left and right and flashes the boxes red one after another, for half a second only, while the line below rolls to say so. With the right code the characters fly to the centre as they shrink, the outer ones first, the boxes dim, the pill tightens to “+$25 credit”, the tick draws itself, and the credit rolls digit by digit from $15.00 to $40.00, turning violet for a moment. A click on the credit pill brings it back to Redeem code.

How it works

Three faces, one pill

Inside the pill sit three stacked faces: Redeem code, the field with its boxes and Apply, and +$25 credit. The script measures them with getBoundingClientRect and takes the pill’s width to the face on show, with back.out for the spring; the pill stays centred because it is shifted by -50% and grows on both sides. The sizes are measured again once the font has arrived and on resize.

The boxes follow a real field

Over the boxes lies a transparent input that takes the keyboard, pasting and the phone: whenever it changes, the text is cleaned (capitals, only letters and digits, eight at most) and the boxes redraw by comparing before and after, so only the new character springs in and only the deleted one leaves.

Wrong, right

Apply compares it with the right code. Wrong: the pill shakes with keyframes on x and each box lights its red layer for half a second, staggered by twenty milliseconds. Right: the characters fly to the centre of the field, measured on the spot, the farthest first, then the face changes, the tick draws itself with stroke-dashoffset (autoRound off) and the credit rolls.

Rolling digits

The credit is made of columns: each digit is a 0 to 9 strip inside a window one line tall, and GSAP takes it to the new digit with yPercent and a small back.out, one column after the other.

Values to change

NameFileDefaultWhat it changes
GOOD_CODEscript.jsLUMA2026The right code, eight letters or digits: the one that gives the credit.
CREDITscript.js25How many dollars the right code adds.
START_BALANCEscript.js15The credit already there before the code, in dollars.
SPRINGscript.js1.6How far the pill overshoots when it changes width (0 = no bounce).
TYPE_SPEEDscript.js0.11The time between characters in the self-running tour, in seconds.
SHAKEscript.js7How far a wrong code shakes the pill, in pixels.
DONE_HOLDscript.js2.4How long “+$25 credit” stays before the self-running tour starts again, in seconds.

Try them in the Playground

When to use it

In an online shop’s cart or checkout, on the gift page, in a subscription app: wherever a promo code or a gift card number gets pasted.

On phones

The pill drops to 52 pixels and the boxes are sized on the width (between 22 and 34 pixels), so the whole field with Apply fits; a tap on the boxes opens the keyboard, and there is no hover.

With reduced motion

No springs, no shake and no flying characters: the faces crossfade, the width jumps to the new size, the red boxes flash in place and the credit changes without rolling. The self-running tour does not start.

Pitfalls

  • The boxes are not one input each: a single transparent input over the eight takes the keyboard, pasting and autofill, and the boxes are only the drawing; with eight inputs pasting breaks and the phone jumps from field to field.
  • The pill’s width is measured on the face, not written: with the variable font arriving later, a size taken too early leaves the words clipped.
  • The centre the characters fly to is measured at the moment of the click: measured earlier, after a resize they would fly sideways.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

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

Testing

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