Skip to content
animorio
IT
Back to the library

Spending limit

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

A card’s monthly spending limit, in a dark card: a bar with what is spent in green and a pale handle, the limit, to drag with its tag above. What is left recounts in large figures as the handle moves, with the spend per day until the new month. When the limit gets close to what is spent the card turns amber, “Close to limit”; when it drops under, the extra stretch turns red, the number says how far over you are, the bar shakes its head and new payments will be declined. Three ready limits to tap.

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>
<!--
  "Spending limit" 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>Spending limit</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 card's monthly spending limit: the bar shows what is spent, the handle is the limit to drag; what is left
         recounts, and when the limit goes under what is already spent the card turns to its warning state -->
    <section class="sp" data-sp aria-label="Card spending limit">
      <header class="sp__head">
        <svg class="sp__card" viewBox="0 0 34 24" aria-hidden="true"><rect x="1" y="1" width="32" height="22" rx="5"></rect><path d="M1 8.500h32"></path><path class="sp__chipline" d="M6 16.500h7"></path></svg>
        <div class="sp__what"><strong>Everyday card</strong><span>Ending in 4821</span></div>
        <span class="sp__pill"><span class="sp__clip"><span data-outpill>On track</span></span></span>
      </header>

      <div class="sp__read">
        <strong class="sp__big"><b data-outleft>$412</b><span class="sp__clip sp__clip--word"><span data-outword>left</span></span></strong>
        <span class="sp__clip sp__clip--sub"><span data-outsub>$788 spent of $1,200</span></span>
      </div>

      <div class="sp__meter" data-meter>
        <span class="sp__tag" data-tag aria-hidden="true"><b data-outtag>$1,200</b></span>
        <div class="sp__bar" data-bar>
          <i class="sp__room" data-room></i>
          <i class="sp__spent" data-spent></i>
          <i class="sp__over" data-over></i>
        </div>
        <span class="sp__handle" data-handle role="slider" tabindex="0" aria-label="Monthly spending limit" aria-valuemin="200" aria-valuemax="2000" aria-valuenow="1200" aria-valuetext="1,200 dollars"><i></i></span>
        <div class="sp__scale" aria-hidden="true"><span>$0</span><span>$1k</span><span>$2k</span></div>
      </div>

      <div class="sp__presets" role="group" aria-label="Quick limits">
        <button type="button" class="sp__preset" data-preset="800" aria-pressed="false">$800</button>
        <button type="button" class="sp__preset" data-preset="1200" aria-pressed="true">$1,200</button>
        <button type="button" class="sp__preset" data-preset="1600" aria-pressed="false">$1,600</button>
      </div>
      <p class="sp__foot"><span class="sp__clip"><span data-outfoot>About $34 a day until it resets</span></span><span class="sp__days">12 days</span></p>
    </section>
    <span class="live" aria-live="polite" data-live></span>

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

28 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 “Spending limit” 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 black, a dark rounded card with a thread of light on its top edge: at the top the drawing of a card with a small green line, “Everyday card”, “Ending in 4821” and on the right the green pill “On track”. Below, large, “$412” with “left” beside it, and the line “$788 spent of $1,200”. Then the bar: the solid green stretch is what is spent, the tinted stretch reaches the limit, and on the limit sits a pale vertical handle with the tag “$1,200” above it; under it the scale “$0”, “$1k”, “$2k”. Three buttons, “$800”, “$1,200” with a green border, “$1,600”, and at the bottom “About $34 a day until it resets” and “12 days”. At the start the spent stretch fills and the handle reaches its place. Dragging the handle to the left the tag follows, the large number goes down fifty at a time and the line below rewrites itself. Close to what is spent the pill, the card’s small line and the tinted stretch turn amber and the pill rolls to “Close to limit”. Under what is spent, the piece of bar past the handle turns red, the number turns red and says “$88” “over”, the pill “Over limit”, the bar shakes once and at the bottom you read “New payments will be declined”. Tapping “$1,600” the handle glides right with a small bounce and everything is green again. Tab reaches the handle: the arrow keys move fifty dollars.

How it works

Two numbers and a state

What is spent and the limit. From the limit asked for comes the state: over if it is under what is spent, close if what is left is less than fifteen per cent, otherwise fine.

The picture follows an animated number

The drawn limit chases the one asked for; from it come the handle’s position, the tinted stretch, the red piece past the limit, the tag and the large number.

The state changes colours in one place

A class on the card changes one variable, `--tone`: pill, tinted stretch and the card’s small line read it and fade together.

Crossing the line

Only on entering the “over” state the bar shakes once; the texts roll in the direction the limit moved.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#3ddc97The colour of all being well: what is spent, the chosen preset, the pill.
SPENTscript.js788How many dollars have already been spent this month.
LIMITscript.js1200The spending limit at the start, in dollars (200 to 2000).
NEARscript.js15Under this percentage of the limit still free, the card warns you are close.
DAYSscript.js12How many days are left until the new month: it gives the spend per day.
LOOPscript.jstrueLeft alone, the demo’s pointer lowers the limit to under what is spent and then raises it again.

Try them in the Playground

When to use it

In the card controls of a banking or fintech app, in company cards with a cap per employee, in a teen account run by parents; the same pattern, a used share and a cap to move with a warning when they cross, carries phone data, cloud storage, a campaign budget or an API limit.

On phones

The card is at most 348 pixels wide and about 300 tall. The handle is grabbed on a 32 by 30 pixel area, with `touch-action: none`; you can also tap the bar at a point or use the three ready limits. The tag always stays inside the bar, at both ends too.

With reduced motion

No glides, bounces or shake: handle, bar and numbers go straight to the limit asked for, the colours change without fading and the texts without rolling. The demo’s pointer does not start.

Pitfalls

  • The warning is not told by colour alone: the pill writes “Close to limit” or “Over limit”, beside the number there is “left” or “over”, and every change of state is announced to screen readers.
  • The state is read from the limit asked for, not the drawn one: otherwise during the handle’s bounce the card would go from amber to green twice.
  • The handle is a `role="slider"` snapping every fifty dollars; the large number, while the handle glides, rounds to tens so it does not jitter.
  • The tag is centred on the handle but held inside the bar: its width is measured again at every draw, because it changes with the figures.
  • While dragging, the “spent of” line is rewritten at once: rolling it at every step it would never be readable.
  • Card, figures and days are invented.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 3 December 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