Skip to content
animorio
IT
Back to the library

Trip fuel gauge

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

A car trip’s fuel use on a dark card: an arc gauge with a scale from 3 to 12 litres per hundred kilometres, the needle, the teal arc following it and the figure below. Hovering “Town”, “Country” or “Motorway” sends the needle towards that leg’s fuel use on a real spring: it overshoots, comes back, swings and settles, and the figure reads the needle at every instant; below, kilometres, litres and cost roll.

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>
<!--
  "Trip fuel gauge" 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>Trip fuel gauge</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 fuel use of a car trip on an arc gauge: a needle on a real spring that swings and settles
         between town, country roads and motorway, with the litres and the cost rolling -->
    <article class="fg" data-fg aria-label="Trip fuel use">
      <header class="fg__head"><strong>Lisbon to Sagres</strong><span>312 km · Saturday</span></header>
      <div class="fg__dial">
        <svg data-svg viewBox="0 0 240 136" aria-hidden="true">
          <path class="fg__track" data-track></path>
          <path class="fg__fill" data-fill></path>
          <g class="fg__ticks" data-ticks></g>
          <line class="fg__needle" data-needle x1="120" y1="112" x2="120" y2="58"></line>
          <circle class="fg__hub" cx="120" cy="112" r="7"></circle>
        </svg>
        <div class="fg__read"><strong data-outnow>6.5</strong><span>L/100 km</span></div>
      </div>
      <div class="fg__tabs" role="tablist" aria-label="Part of the trip" data-tabs>
        <i class="fg__pill" data-pill aria-hidden="true"></i>
        <button type="button" role="tab" data-leg="trip" aria-selected="true">Whole trip</button>
        <button type="button" role="tab" data-leg="town" aria-selected="false" tabindex="-1">Town</button>
        <button type="button" role="tab" data-leg="country" aria-selected="false" tabindex="-1">Country</button>
        <button type="button" role="tab" data-leg="motorway" aria-selected="false" tabindex="-1">Motorway</button>
      </div>
      <footer class="fg__foot"><span data-outnote>312 km · 20.2 L of fuel · $36.39</span></footer>
    </article>
    <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.

20 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 “Trip fuel gauge” 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 rounded dark card: “Lisbon to Sagres” and on the right “312 km · Saturday”. In the middle an arc gauge: the grey track, a tick for every litre and the numbers 3, 6, 9 and 12, a light needle with its hub and a teal arc running from the start of the scale to the needle; below, the large figure, “6.5”, and “L/100 km”. Then the bar of the legs, “Whole trip”, “Town”, “Country”, “Motorway”, with the pill behind the chosen one, and at the bottom a line with kilometres, litres and cost. On entering the needle is let go from the bottom of the scale and settles with a swing. Hovering “Town” (or tapping it) springs the pill there and the needle shoots towards 8.9: it overshoots, comes back, swings two or three times less and less and stops; the teal arc and the figure follow it the whole time, so the figure swings too. “Country” drops it to 5.2, “Motorway” to 6.6. If the leg changes while it is still swinging, it carries on from the speed it had.

How it works

A mass on a spring

The needle is not a tween: it has a position and a velocity. On every frame one force pulls it towards the target in proportion to the distance (STIFF) and another slows it in proportion to its speed (DAMP). The overshoot and the settling come from that, with no drawn curves.

Small steps, capped time

The time between two frames is capped at a thirtieth of a second and split into four steps: that way the spring does not blow up if the tab stalled for a moment. When position and velocity are almost zero the loop turns off and nothing is redrawn.

From value to arc

A value becomes an angle on the scale’s two hundred degrees, and the angle a point on the circle: from it come the needle’s tip, the end of the teal arc (a path with the A command rewritten every time) and the ticks, written by the script.

The figure reads the needle

The number under the gauge has no animation of its own: it writes the needle’s position on every frame. That is why it goes past the value and then comes back, as on a real instrument.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#35d0baThe colour of the fuel-use arc.
STIFFscript.js90How stiff the needle’s spring is: higher means quicker.
DAMPscript.js7How much it is damped: lower means more swings before it stops.
PRICEscript.js1.8The price of a litre of fuel.
HOLDscript.js2.4How many seconds the demo’s pointer stays on each leg.
LOOPscript.jstrueLeft alone, the demo’s pointer goes over the legs of the trip.

Try them in the Playground

When to use it

In the trip summary of a car, rental or navigation app, where a single number (fuel use) changes with the leg; the same gauge with its spring needle carries a connection’s speed, a server’s load, heart rate during a workout or a product’s average rating by category.

On phones

The card is at most 340 pixels wide and about 345 tall; the gauge is sized on the screen’s height too, so in a phone’s box it shrinks instead of spilling out. With a finger the legs are tapped.

With reduced motion

No spring: the needle, the arc and the figure are at the chosen leg’s value at once, the pill is already in place and the bottom line changes without rolling. The demo’s pointer does not start.

Pitfalls

  • A spring integrated with too long a time step diverges: after a background tab the needle would shoot off. That is why the step is capped at a thirtieth of a second and split in four.
  • With a very low DAMP the needle swings for a long time and would go past the ends of the scale: the angle is kept just beyond the minimum and maximum, the value is not, so the physics stays right.
  • The legs are tabs (a tablist) changed with the arrow keys; an aria-live region gives the leg’s final fuel use, not the values of the swing, which read aloud would be just noise.
  • Trip, kilometres, fuel use and price are invented; the whole trip’s fuel use is worked out from the three legs, not typed in.

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