Skip to content
animorio
IT
All components

Spending donut chart

Charts, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 8.0 KBGSAP 28 KBFreeDownload the zip

The spending card of a budgeting app, clean as a real product piece, on white: a donut in five tones of one colour draws itself slice after slice and the total rolls digit by digit in the middle. Point at a slice, or at its row, and it lifts out and thickens on a spring, the others dim and the centre tells how much and what share; Week, Month and Year bend the slices to the new shares.

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 donut chart" 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 spending donut chart that opens on hover</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 spending card of a budgeting app: a donut drawn in five tones of one colour, the total rolling in the middle,
         a Week / Month / Year switch that bends the slices to the new shares, and a slice that opens when you point at it -->
    <section class="spend" data-card aria-label="Fennel spending">
      <header class="spend__head">
        <div class="spend__title">
          <svg class="spend__mark" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3.5c3.8 2.6 5.7 5.7 5.7 9.1a5.7 5.7 0 0 1-11.4 0c0-3.4 1.9-6.5 5.7-9.1Z"></path><path class="spend__vein" d="M12 9v10.2"></path></svg>
          <div>
            <p class="spend__name">Spending</p>
            <p class="spend__range" data-range>Oct 1 &ndash; Oct 26</p>
          </div>
        </div>
        <div class="tabs" role="tablist" aria-label="Period" data-tabs>
          <span class="tabs__pill" data-pill aria-hidden="true"></span>
          <button class="tabs__tab" role="tab" type="button" data-period="week" aria-selected="false">Week</button>
          <button class="tabs__tab is-on" role="tab" type="button" data-period="month" aria-selected="true">Month</button>
          <button class="tabs__tab" role="tab" type="button" data-period="year" aria-selected="false">Year</button>
        </div>
      </header>

      <div class="spend__body">
        <div class="donut" data-donut>
          <svg class="donut__svg" viewBox="0 0 200 200" aria-hidden="true">
            <circle class="donut__track" cx="100" cy="100" r="74"></circle>
            <g data-slices></g>
          </svg>
          <div class="donut__center" aria-live="polite">
            <p class="donut__label" data-center-lab>Total spent</p>
            <p class="donut__value" data-center-val></p>
            <p class="donut__note" data-center-note></p>
          </div>
        </div>

        <ul class="legend" data-legend></ul>
      </div>

      <footer class="spend__foot">
        <svg class="spend__trend" viewBox="0 0 16 16" aria-hidden="true" data-trend><path d="M3 5.5 8 10.5l5-5"></path></svg>
        <p class="spend__insight" data-insight>12% less than September</p>
      </footer>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></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.

23 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 “Spending donut chart” 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 sits the Spending card of Fennel, an invented budgeting app: the leaf mark, the period «Oct 1 – Oct 26» and on the right the Week, Month, Year switch with the white pill on Month. Below, on the left, a donut in five tones of indigo, from the darkest to the lightest, split by a thread of white: on arrival the slices draw themselves one after another and in the middle «Total spent» and the total, $2,846, roll digit by digit from the right, with «this month» underneath. On the right the legend: Bills, Groceries, Dining out, Shopping and Transport, each with its rolling figure and a thin bar in its tone that grows. Point at a slice, or at its row, and it lifts outwards by a few units and thickens on a spring that goes a hair too far, the other slices and rows dim, the row slides two pixels and the centre changes: the category name, its rolling figure and «37% of total». Choosing Year or Week, the pill stretches towards the new tab and its tail catches up on a spring, the chosen label widens on the wdth axis, the slices bend to the new period’s shares one after another while the donut takes a small breath, total, figures and bars follow, and at the bottom the comparison line changes with its arrow turning over: green when you spend less, grey when you spend more. A drawn pointer does it all by itself and starts again; it also really works, with mouse, finger and keyboard.

How it works

Slices made of angles

Each slice is an SVG arc path, redrawn on every frame from its two angles, how much of it is drawn, its thickness and its lift: GSAP does not animate the drawing but a small object holding those numbers, and onUpdate rewrites the d attribute. The angles come from the period’s shares, leaving 2.4 degrees of white between one slice and the next.

Bending instead of redrawing

Changing period erases nothing: each slice goes with power3.inOut from its angles to the new ones, three hundredths apart, so the donut bends like a single object. Meanwhile the donut dips to 97.5% and comes back, a breath.

The slice that opens

On hover the slice goes to a bigger thickness and moves outwards along its bisector, with a back.out that overshoots by a hair; the others drop to a quarter of their opacity. Slice and legend row call the same function.

Rolling digits

Each digit is a window one line tall holding a column from 0 to 9: GSAP moves it in yPercent to the right digit, starting from the right with a small delay per place. If the number gets longer, the old digits stay aligned to the right and the new ones are born on the left.

The autopilot

A sequence of steps built on the tweens’ promises takes the drawn pointer to the real spot of each slice, computed from its angles and the donut’s size, opens the slice and presses the period tabs. At the first real gesture it stops, and it starts again after eight quiet seconds.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#4f46e5The donut’s colour: the five slices are its tones, from darkest to lightest.
DRAW_TIMEscript.js0.6The seconds each slice takes to draw itself on arrival.
MORPH_TIMEscript.js0.8The seconds the slices take to bend to the new shares when you change period.
LIFTscript.js5How far the pointed slice lifts out of the donut.
THICKENscript.js6How much the pointed slice thickens.
PAUSEscript.js1.2The seconds the autopilot stays on each slice.

Try them in the Playground

When to use it

For the dashboard of a finance or budgeting app, the spending summary of an online bank, a shop’s statistics split by category, any total to explain in parts.

On phones

The card takes the width of the box, the donut drops to 40vw or 36vh and the legend stays beside it; under 380 pixels the period tabs and the rows tighten a little. A tap on a slice or a row opens it like the mouse hover.

With reduced motion

No lifts and no springs: the pointed slice only thickens and the others dim, the change of period is a fade of the donut, the figures change without rolling and the drawn pointer stays hidden.

Pitfalls

  • With tabular figures Mona Sans draws a slashed zero: the digit columns keep their own width and no tabular-nums.
  • An SVG arc from an angle to itself vanishes or draws a full circle depending on the browser: under a twentieth of a degree the path stays empty.
  • The spot where the drawn pointer opens a slice must be recomputed at every step from the angles of that moment, because after a change of period the slices are elsewhere.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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