Skip to content
animorio
IT
All components

Pocket calculator

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

A calculator that really works, its keys pressing on a spring. Each digit steps into the display from below and settles, the chosen operation stays lit blue until the second number arrives, and on equals the sum moves up, small, while the result rolls in digit after digit. It works from the keyboard too.

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>
<!--
  "Pocket calculator" 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>Pocket calculator</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">
    <!-- a pocket calculator: the keys press on a spring, each digit steps into the display
         and on equals the sum moves up, small, while the result rolls in -->
    <section class="cl" data-cl aria-label="Calculator">
      <div class="cl__screen">
        <span class="cl__sum"><span data-outsum></span></span>
        <output class="cl__value" data-outvalue aria-live="polite">0</output>
      </div>
      <div class="cl__pad">
        <button class="cl__key is-fn" type="button" data-key="clear" aria-label="Clear"><span>AC</span></button>
        <button class="cl__key is-fn" type="button" data-key="sign" aria-label="Plus or minus"><span>±</span></button>
        <button class="cl__key is-fn" type="button" data-key="percent" aria-label="Percent"><span>%</span></button>
        <button class="cl__key is-op" type="button" data-key="/" aria-label="Divide"><span>÷</span></button>
        <button class="cl__key" type="button" data-key="7"><span>7</span></button>
        <button class="cl__key" type="button" data-key="8"><span>8</span></button>
        <button class="cl__key" type="button" data-key="9"><span>9</span></button>
        <button class="cl__key is-op" type="button" data-key="*" aria-label="Multiply"><span>×</span></button>
        <button class="cl__key" type="button" data-key="4"><span>4</span></button>
        <button class="cl__key" type="button" data-key="5"><span>5</span></button>
        <button class="cl__key" type="button" data-key="6"><span>6</span></button>
        <button class="cl__key is-op" type="button" data-key="-" aria-label="Minus"><span>−</span></button>
        <button class="cl__key" type="button" data-key="1"><span>1</span></button>
        <button class="cl__key" type="button" data-key="2"><span>2</span></button>
        <button class="cl__key" type="button" data-key="3"><span>3</span></button>
        <button class="cl__key is-op" type="button" data-key="+" aria-label="Plus"><span>+</span></button>
        <button class="cl__key is-wide" type="button" data-key="0"><span>0</span></button>
        <button class="cl__key" type="button" data-key="." aria-label="Decimal point"><span>.</span></button>
        <button class="cl__key is-eq" type="button" data-key="=" aria-label="Equals"><span>=</span></button>
      </div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></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.

29 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 “Pocket calculator” 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 white, a light calculator with soft corners: at the top the white display with a large zero on the right, below four columns of keys (AC, plus or minus and percent in grey, the four operations in pale blue, the digits white, the zero two keys wide and the solid blue equals). On opening the keys appear starting from the last. Press a key and it squashes and springs back, its label dropping two pixels; the digit steps into the display from below, small, and settles, with the thousands separators in place. Pick an operation and its key stays lit blue while what has been typed so far appears above, small. On equals the whole sum moves up into the small line and the result rolls in one digit after the other; a long number narrows to fit the display. Dividing by zero writes “Error” and shakes the display. The keyboard keys work too, with Enter, Esc and Backspace.

How it works

The sum

Four things in memory: the number being typed (as text), the one before, the operation waiting and whether the next digit starts afresh. An operation pressed after the second number works the pending sum out first, as real calculators do.

The digits in the display

On every key the number is rewritten, one character per element, with thousands separators. While typing only the last digit animates, from below; on a result they all rise, staggered by four hundredths of a second.

The keys

Each key is a button with data-key. On press GSAP takes it from scale 0.88 to 1 on an elastic spring; the waiting operation takes a class that keeps it lit.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#3b6cf6The colour of the operation keys and of equals.
PRESSscript.js0.55How long a key takes to come back after a press.
SPRINGscript.js1How much keys and digits bounce.

Try them in the Playground

When to use it

Inside an expenses app, a back-office tool, a quote builder, a shop’s till; on a site selling by the metre or the kilo, next to the price; and as the keypad for any number entered by hand, from a bill to split to a tip.

On phones

The calculator is at most 244 pixels wide and about 340 tall; on low screens the keys get shorter. Each key is over 50 pixels wide: easy to press with a thumb.

With reduced motion

The keys do not squash and the digits do not rise: the number changes in place and the sum appears already in the small line. The display does not shake on an error. The demo’s pointer does not start.

Pitfalls

  • Decimal numbers in JavaScript get the last digit wrong (0.1 plus 0.2): every result is rounded to nine significant digits before being written.
  • The display is an output element with aria-live: a screen reader hears the number on every change. The sign keys carry a label in words (Divide, Multiply).
  • The minus, times and divide signs are the real characters, not the hyphen and the x: in the script they are written with String.fromCharCode.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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