Skip to content
animorio
IT
Back to the library

Unit-changing counter

TextGSAP, CSS onlyMediumCompressed weight: Demo 5.8 KBGSAP 28 KBFreeDownload the zip

The figures of a made-up app, Murrow, in the clean style of interface pieces: three large figures count up and, when they pass a thousand or a million, the unit changes with a small show. The extra digits squeeze and slide away, the point drops into place, the K or the M arrives narrow and widens, lit blue for a moment, and the figure goes one pixel past its place and settles.

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>
<!--
  "Unit-changing counter" 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 counter with numbers that grow and change units</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 numbers of a made-up team chat app, Murrow: three figures count up, and when one passes a thousand or a
         million its unit changes with a small show, the extra digits squeeze and slide away, the decimal point drops
         into place and the K or the M arrives narrow and widens -->
    <section class="stats" aria-label="Murrow in numbers" data-frame>
      <p class="eyebrow"><span class="mark" aria-hidden="true"><svg viewBox="0 0 20 20"><path d="M3.5 5.5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H9l-3.6 3v-3H5.5a2 2 0 0 1-2-2z"/></svg></span><span data-brand>Murrow</span> <span class="eyebrow__soft">in numbers</span></p>
      <h1 class="title">Built by teams like yours</h1>

      <div class="grid">
        <div class="stat" data-stat="0">
          <p class="stat__label">Teams</p>
          <p class="num" data-num aria-live="off"></p>
          <span class="rule" aria-hidden="true"><span class="rule__fill" data-rule></span></span>
          <p class="stat__note" data-note>since launch</p>
        </div>
        <div class="stat" data-stat="1">
          <p class="stat__label">Messages sent</p>
          <p class="num" data-num aria-live="off"></p>
          <span class="rule" aria-hidden="true"><span class="rule__fill" data-rule></span></span>
          <p class="stat__note" data-note>this month</p>
        </div>
        <div class="stat" data-stat="2">
          <p class="stat__label">Hours saved</p>
          <p class="num" data-num aria-live="off"></p>
          <span class="rule" aria-hidden="true"><span class="rule__fill" data-rule></span></span>
          <p class="stat__note" data-note>by fewer meetings</p>
        </div>
      </div>

      <button class="replay" type="button" data-replay data-autoclic>
        <svg viewBox="0 0 20 20" aria-hidden="true"><path d="M4.5 10a5.5 5.5 0 1 0 1.7-4"/><path d="M4 3.5v3.2h3.2"/></svg>
        <span>Replay</span>
      </button>
    </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.

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 “Unit-changing counter” 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 warm white background, at the top, the mark of Murrow, a made-up team chat, with «in numbers» and the headline Built by teams like yours. Below, three large figures in Mona Sans: Teams, Messages sent and Hours saved, each with a thin line under it and a grey note. The figures count up and the digits that change roll: the old one goes up and away, the new one comes from below. When a figure passes a thousand its unit changes: 980 becomes 1.2K, the old digits squeeze on the width axis and slide away one after another, the new ones roll up, the decimal point drops into place from above with a little knock and the K comes in narrow, widens past its size and comes back, lit blue for a moment. The whole figure goes one pixel past its place and settles. With each larger unit the digits get heavier; the second figure reaches 3.4M with the same show. Under each figure the line grows towards the end. At the end of the loop Replay appears, then the figures go back to zero and start again.

How it works

One cell per character

Each figure is a row of spans, one per character, each with its font-variation-settings tied to two CSS variables, --w for the width and --g for the weight. GSAP animates the variables directly, so every digit can squeeze, widen or get heavier on its own.

The rolling digits

While the figure counts, a tween on an object takes the value to its goal and every update writes the new text. Only the digits that changed roll: the old one goes up by its whole height inside the cell with overflow hidden, the new one arrives from below in sixteen hundredths.

The change of unit

At the threshold the old cells, from the last to the first, go to zero width while --w drops to 62 and the opacity to zero. The new ones start at zero width and grow to the size measured beforehand; the digits rise with back.out, the point drops from above on a stronger spring and the K or the M goes from --w 75 to 118 and back to 100 with elastic.out, its accent colour fading into black.

Weight and settling

The weight depends on the unit, plus WEIGHT_STEP at each jump, and a little on the value inside the unit; in the change it arrives forty points heavier and settles. The whole row goes up one pixel and comes back with an elastic.

The line and the loop

The line under each figure grows on a logarithmic scale, so both the small and the large steps show. A single timeline lines up the steps of the three figures, offset by thirty-five hundredths; at the end Replay appears and the loop starts again.

Values to change

NameFileDefaultWhat it changes
BRANDscript.js"Murrow"The name of the made-up app, written above the headline.
COUNTscript.js1.4The seconds a figure takes to count to the next step.
MORPHscript.js0.75The seconds of the change of unit.
WEIGHT_STEPscript.js110How much weight the digits gain with each larger unit.
OVERSHOOTscript.js1The pixels the figure goes past its place before settling.
HOLDscript.js2.6The seconds the finished figures stay before the loop starts again.

Try them in the Playground

When to use it

For the stats section of a landing page, a report or an app: three figures that count up and, instead of growing long, change unit the way they are really written, 1.2K and 3.4M.

On phones

The same animation with adapted sizes: under 560 pixels the three figures become rows, with the name and the note on the left and the figure on the right, and the size of the digits follows the width and the height.

With reduced motion

No counting and no rolling: the finished figures appear at once with a fade, with full lines.

Pitfalls

  • A cell that changes width has to be measured first: the new cell goes into the page, offsetWidth is read and only then is it taken to zero, otherwise the row jumps when the K arrives.
  • While the figure counts fast, a digit can change again before it has finished rolling: in that case it is simply written, without a second tween on top of the first.
  • The point and the K change the shape of the string: from 9.9K to 10.0K the length changes, and there the row is rewritten with a small roll of all the digits instead of comparing them one by one.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 27 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 animations