Skip to content
animorio
IT
Back to the library

Unit converter

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

Someone searched for “unit converter” and the site only found things close to it. Here is the unit converter of a made-up cooking app, Mise, in a single card on warm white: at the top the Weight, Volume and Temp categories in a segmented control with a sliding pill; below, two large rows, 250 g and 8.82 oz, with rolling digits. The value changes by dragging a thin ruler with ticks: you fling it, it glides and springs onto the tick under the needle. The button with two arrows turns half a turn and the two rows swap places; with Temp the ruler warms slightly from blue to terracotta, and a small line underneath says what it amounts to: “≈ 2 cups of flour”, “≈ gas mark 4”. Minimal style.

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 converter" 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>Unit converter</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">
    <!-- the unit converter of a made-up cooking app, Mise: three categories in a segmented control, the value and
         its conversion in two rows that swap places, a thin ruler to drag with inertia and a spring on the ticks -->
    <section class="card" data-card aria-labelledby="uc-title">
      <header class="head">
        <span class="brand"><svg viewBox="0 0 18 18" aria-hidden="true"><path d="M3 12.5h12M4.6 12.5a4.4 4.4 0 0 1 8.8 0M9 8.1V6.2M7.6 6.2h2.8"></path></svg>Mise</span>
        <h1 class="head__title" id="uc-title">Converter</h1>
      </header>

      <div class="seg" role="tablist" aria-label="Category" data-seg>
        <span class="seg__pill" data-pill aria-hidden="true"></span>
        <button class="seg__btn" type="button" role="tab" data-cat="weight" aria-selected="true">Weight</button>
        <button class="seg__btn" type="button" role="tab" data-cat="volume" aria-selected="false">Volume</button>
        <button class="seg__btn" type="button" role="tab" data-cat="temp" aria-selected="false">Temp</button>
      </div>

      <div class="rows" data-rows>
        <div class="row row--from" data-row="a">
          <div class="row__num"><span class="roll" data-val></span><span class="row__sym" data-sym></span></div>
          <span class="row__name" data-name></span>
        </div>
        <div class="rows__rule" aria-hidden="true"></div>
        <div class="row row--to" data-row="b">
          <div class="row__num"><span class="roll" data-val></span><span class="row__sym" data-sym></span></div>
          <span class="row__name" data-name></span>
        </div>
        <button class="swap" type="button" data-swap aria-label="Swap units">
          <span class="swap__bg" aria-hidden="true"></span>
          <svg class="swap__ic" viewBox="0 0 20 20" aria-hidden="true" data-swap-ic>
            <path d="M6.5 15.5V4.5M3.6 7.4l2.9-2.9 2.9 2.9"></path>
            <path d="M13.5 4.5v11M10.6 12.6l2.9 2.9 2.9-2.9"></path>
          </svg>
        </button>
      </div>

      <div class="ruler" data-ruler role="slider" tabindex="0" aria-label="Amount" aria-valuemin="0" aria-valuemax="1000" aria-valuenow="250">
        <span class="ruler__tint" data-tint aria-hidden="true"></span>
        <div class="ruler__win">
          <svg class="ruler__strip" data-strip aria-hidden="true"></svg>
        </div>
        <span class="needle" data-needle aria-hidden="true"><span class="needle__cap"></span></span>
      </div>

      <p class="hint"><span class="hint__approx" aria-hidden="true">&asymp;</span><span class="hint__txt" data-hint></span></p>
    </section>

    <svg class="ptr" data-ptr viewBox="0 0 24 24" aria-hidden="true"><path d="M5.2 3.4l13 8.2-5.6 1.3 3.3 5.9-2.4 1.3-3.3-5.9-4 4.1z"></path></svg>
    <p class="sr" aria-live="polite" data-live></p>
  </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.

27 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 “Unit converter” 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, a card with a soft multi-layer shadow and a thread of light on its edge. At the top the mark of Mise, a made-up cooking app, then the Weight, Volume, Temp segmented control: the white pill slides under the chosen category on a spring and squashes slightly as it lands. Below, two rows: the starting value in black and the converted one in terracotta, large, in variable Mona Sans, with digits rolling one by one; between them a thin line and the round button with two arrows. The ruler at the bottom has short, medium and long ticks with numbers, fades at the sides, and the terracotta needle in the middle marks the value: the ticks near the needle grow as if under a lens. You drag it: the number narrows a little if you fling hard, the ruler glides, passes the tick by a hair and springs onto it; the needle gives a small kick at each tick. The arrows button turns half a turn and the two rows swap places, passing over each other while their colours swap; the ruler changes scale. With Temp the ticks run from blue to terracotta and a glow under the needle warms with the value. At the bottom “≈ 2 cups of flour”, “≈ 1 cup of milk” or “≈ gas mark 4, a moderate oven” changes by rising. On its own it drags the ruler, switches to Temp, swaps the units, tries Volume and goes back to Weight.

How it works

A ruler that is an SVG strip

The ruler is an SVG as long as all the unit's ticks (one tick every TICK_GAP pixels), inside a window with a mask that fades the sides. The position is a number in the top row's unit: the strip moves with x = half the window minus the tick index times the gap. The ticks nearest the needle grow on a gaussian, recalculated at each step on nine ticks only.

Fling, glide and spring

While dragging the velocity is measured (moving average); on release the landing point is the position plus velocity times GLIDE, snapped to the nearest tick and kept within the limits. On a long trip a timeline goes a hair past with power3.out and comes back with elastic.out; on a short one a back.out is enough. Past the limits the drag gives a third, like a rubber band.

Rolling digits

Each digit is a window one line tall holding the column from 0 to 9, moved with yPercent: when the value changes each digit rolls only as far as it needs, with a small delay from right to left. While the ruler runs the numbers follow the ticks, not the values in between.

The swap

A tween from 0 to 1 moves the two rows into each other's place, measuring the distance on every frame (so it holds even if the window changes height), with a back.out and a small shrink halfway; the colours swap along. At the end the units really invert and the transforms are cleared: the result is identical to the last frame.

Values to change

NameFileDefaultWhat it changes
START_GRAMSscript.js250The starting weight, in grams.
START_MLscript.js240The starting volume, in millilitres.
START_Cscript.js180The starting temperature, in degrees Celsius.
TICK_GAPscript.js8The distance between two ruler ticks, in pixels.
GLIDEscript.js0.3How far the ruler glides after a fling.
SNAP_SPRINGscript.js1.6How far it passes the tick before snapping onto it.
ROLL_TIMEscript.js0.5How long the digits take to roll, in seconds.
SWAP_TIMEscript.js0.75How long the two rows take to swap, in seconds.
LOOP_PAUSEscript.js2.2The pause at the end of the loop before it starts again.
--accentostyle.css#d0532aThe accent colour: needle, converted value, ≈ sign.

Try them in the Playground

When to use it

In a recipe app or site, next to the ingredients; on a cooking or baking blog; in a shop for kitchen tools or scales; in a dashboard that has to convert measurements without a keyboard, with a thumb.

On phones

The card takes the width with a margin and the spacing, numbers and ruler also follow the height with clamp and vh; when the box is short the mark at the top hides, and under 340 pixels wide the unit names disappear. The ruler is rebuilt on every resize, and the swap measures the distance between the rows on every frame. The ruler is dragged with a finger (touch-action pan-y lets the page scroll vertically).

With reduced motion

No glides, springs or rolling digits: the ruler can still be dragged but stops straight on the tick, the numbers change at once, the swap and the category change are fades, and the self-running loop does not start.

Pitfalls

  • Mona Sans tabular digits have a one with a foot and looked typewritten: the digits stay proportional, centred in their column (as wide as the widest digit).
  • The swap rebuilds the ruler halfway, while the units are not inverted yet: the rebuild inverts and restores the state inside the same function, otherwise it drew the old scale.
  • A back.out on a long glide overshot by dozens of ticks: it goes past the tick by a fixed fraction of the step, then an elastic.out brings it back.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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