Skip to content
animorio
IT
Back to the library

EV charging session

SVG, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.5 KBGSAP 28 KBFreeDownload the zip

The charging session of an electric car at a fast charger, live: the battery fills towards its 80% limit, energy and cost count up, the minutes left go down and the power, full at first, tapers as the battery fills, along a curve that draws itself. “Stop charging” halts everything with the power dropping to zero; once the limit is reached, the bolt becomes a tick.

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>
<!--
  "EV charging session" 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>EV charging session</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 live charging session at a fast charger: the battery fills towards its limit, energy and cost count
         up, the power tapers as the battery gets full, and the session can be stopped and resumed -->
    <section class="ev" data-ev aria-labelledby="ev-title">
      <header class="ev__head">
        <span class="ev__bolt" aria-hidden="true"><svg viewBox="0 0 24 24"><path class="bl" d="M13 3.500 6 13.500h5l-1 7 7-10h-5Z"></path><path class="ck" pathLength="1" d="m6 12.500 4 4 8-9"></path></svg></span>
        <span class="ev__name"><b id="ev-title">Volta Hub, bay 4</b><span class="ev__stateroll"><span data-state>Charging, CCS</span></span></span>
        <span class="ev__eta"><b data-eta>14</b><span>min left</span></span>
      </header>

      <div class="ev__battery">
        <svg viewBox="0 0 300 96" aria-hidden="true">
          <defs><clipPath id="ev-cell"><rect x="6" y="6" width="272" height="84" rx="17"></rect></clipPath><clipPath id="ev-level"><rect data-level x="6" y="6" width="0" height="84"></rect></clipPath></defs>
          <rect class="shell" x="2" y="2" width="280" height="92" rx="21"></rect>
          <rect class="cap" x="286" y="32" width="10" height="32" rx="4"></rect>
          <g clip-path="url(#ev-cell)">
            <rect class="fill" data-fill x="6" y="6" width="0" height="84"></rect>
            <g clip-path="url(#ev-level)"><rect class="sheen" data-sheen x="-60" y="6" width="46" height="84"></rect></g>
            <path class="ticks" d="M60.400 6v84M114.800 6v84M169.200 6v84M223.600 6v84"></path>
          </g>
          <path class="limit" data-limit d="M0 0v92"></path>
        </svg>
        <p class="ev__pct"><b data-pct>46</b><span>%</span></p>
        <p class="ev__to"><span data-to>to 80%</span></p>
      </div>

      <dl class="ev__stats">
        <div><dt>Energy</dt><dd><b data-kwh>0.0</b> kWh</dd></div>
        <div><dt>Cost</dt><dd>€<b data-cost>0.00</b></dd></div>
        <div><dt>Power</dt><dd><b data-kw>0</b> kW</dd></div>
      </dl>

      <svg class="ev__curve" viewBox="0 0 300 34" preserveAspectRatio="none" aria-hidden="true">
        <path class="back" data-curve-back d=""></path>
        <path class="front" data-curve pathLength="1" d=""></path>
      </svg>

      <button class="ev__go" type="button" data-go><span class="ev__gotext"><span data-golabel>Stop charging</span></span></button>
    </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.

30 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 “EV charging session” 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 near black, a dark card: a green bolt, “Volta Hub, bay 4”, “Charging, CCS” and on the right the minutes left. In the middle a large battery drawn in SVG, with its terminal on the right: green fills it from the left with a pale sheen crossing it, four dark ticks divide it and a dashed line marks the limit, “to 80%”; on the green the large charge figure, “46%”, going up. Below, three tiles: “Energy” with the kWh, “Cost” with the euros and “Power” with the kW, all in tabular figures counting. Further down a thin curve: the power full and then falling, with the part already travelled in green moving forward. At first the power rises from zero to 120 kW; past 60% it starts to taper, and the minutes left go down more slowly. “Stop charging”: the power glides to zero, the green dims to a grey green, the sheen stops, the state says “Paused, cable still locked” and the button turns green, “Resume charging”. At 80% everything stops by itself: “Charged to 80%”, “at limit”, the bolt withdraws and a tick draws in its place, the card gives a small start and the button says “Unlock cable”.

How it works

Two numbers

The charge and the power shown. A single function draws everything from there: the width of the green (an SVG attribute), the percentage, the kWh, the cost, the minutes and how much of the curve is lit.

Power follows charge

Full up to 60%, then falling in a straight line to a third at 100%. On every frame the charge grows in proportion to the power: that is why it slows towards the end.

The time step

The simulation runs in GSAP’s ticker with time capped at a thirtieth of a second, so a dropped frame does not make the charge jump; when it is paused or full nothing is computed.

The curve

The same path twice: the one behind grey, the one in front green with pathLength 1 and the stroke-dashoffset equal to the part still to go.

Stopping and resuming

The power shown does not jump: a tween takes it to zero on stopping and back to the real value on resuming.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#3ddc84The colour of the charge, of the curve and of charging in progress.
STARTscript.js46The battery’s charge when the session starts, in percent.
LIMITscript.js80The limit at which charging stops, in percent.
PRICEscript.js0.49The price of one kWh, in euros.
POWERscript.js120The charger’s peak power, in kW.
SPEEDscript.js5How many charge points per second at peak power: the demo runs faster than real life.
LOOPscript.jstrueLeft alone, the demo’s pointer stops charging, resumes it and the session starts again.

Try them in the Playground

When to use it

In the app of an electric car, a charging network or a fleet: the screen people watch while the car is plugged in, to know how long is left, how much they are spending and to stop charging from the phone.

On phones

The same card, as wide as the screen minus the margins: the battery is an SVG that tightens with the width, the charge figure shrinks a little and the three tiles stay in a row with tabular figures, so they do not jitter.

With reduced motion

Nothing runs: the session is shown already finished, with the battery at its limit, the final kWh and cost, the whole curve and the tick. The button shows on request the session half way, paused, with no counting. The demo does not move by itself.

Pitfalls

  • Charger, car, prices and powers are made up and nothing is charged: in a real app charge and power come from the car or the charger every few seconds, and would be shown here with the same function.
  • The demo runs fast: SPEED fits in a few seconds what really takes a quarter of an hour; the minutes left are the real ones, worked out from capacity and power.
  • While the battery empties to start again, the simulation is paused: otherwise the tween bringing it back and the count pushing it up would write over each other.
  • The curve uses stroke-dashoffset with pathLength 1 and autoRound off; until the charge has moved the green stroke has zero opacity, so no dot is left.
  • The large figure sits on the green: START does not go below 30, otherwise it would end up on the dark ground and be unreadable.
  • The pause is not told by colour alone: the state writes it, the power goes to zero and the button changes its name.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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