Skip to content
animorio
IT
Back to the library

Battery levels widget

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

Someone searched for “battery” and the site only found buttons and cables with a battery inside. Here is a phone's batteries widget, in a white card on cool paper: the phone, the watch and the earbuds case on three rows, each with its outlined icon, a rolling percentage and a small battery whose liquid fills on a spring with a gently moving surface. The earbuds connect: their row slides in between the others, the green bolt draws itself and a light climbs slowly through the liquid while the charge rises to 100; meanwhile the case drops under 20% and turns red with a single beat. On hover a row opens and says how much is left, “2 h 40 min left”. Minimal style.

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>
<!--
  "Battery levels widget" 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>Batteries widget</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 batteries widget of a phone: every device on a row, a battery that fills with a liquid edge, the
         percentage that rolls, the bolt that draws itself while charging, red under the low limit -->
    <div class="scala">
    <section class="card" data-card aria-labelledby="bw-title">
      <header class="head">
        <div class="head__l">
          <h1 class="head__title" id="bw-title">Batteries</h1>
          <p class="head__sub" data-head-sub>3 devices</p>
        </div>
        <span class="head__ic" aria-hidden="true">
          <svg viewBox="0 0 20 20"><rect x="2.5" y="6" width="13" height="8" rx="2.4"></rect><path d="M17.5 8.6v2.8"></path><path class="head__lv" d="M5 8.5h5.2v3H5z"></path></svg>
        </span>
      </header>

      <ul class="list" data-list>
        <li class="dev" data-dev="phone">
          <button class="dev__main" type="button" aria-expanded="false">
            <span class="dev__ic" aria-hidden="true"><svg viewBox="0 0 24 24"><rect x="7" y="2.8" width="10" height="18.4" rx="2.6"></rect><path d="M10.6 5.4h2.8"></path></svg></span>
            <span class="dev__txt"><span class="dev__name">Phone</span><span class="dev__sub" data-sub>On battery</span></span>
            <span class="dev__pct"><svg class="bolt" viewBox="0 0 12 16" aria-hidden="true"><path pathLength="1" d="M7.2 1.2 2.4 9h3.8l-1.4 5.8L9.6 7H5.8z"></path></svg><span class="roll" data-pct></span><span class="pct">%</span></span>
            <span class="batt" aria-hidden="true"><span class="batt__in"><span class="batt__fill" data-fill><span class="batt__sheen" data-sheen></span><svg class="batt__wave" viewBox="0 0 6 22" preserveAspectRatio="none"><path data-wave></path></svg></span></span><span class="batt__nub"></span></span>
          </button>
          <div class="dev__more" data-more><div class="dev__more-in"><p data-left></p><p class="muted" data-note>Last full charge 9:12</p></div></div>
        </li>

        <li class="dev dev--hidden" data-dev="buds">
          <button class="dev__main" type="button" aria-expanded="false">
            <span class="dev__ic" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M6.4 4.6a3 3 0 0 1 3 3v3.2a1.6 1.6 0 0 1-1.6 1.6H7.2v6.4a1.2 1.2 0 0 1-2.4 0V7.6a3 3 0 0 1 1.6-3z"></path><path d="M17.6 4.6a3 3 0 0 0-3 3v3.2a1.6 1.6 0 0 0 1.6 1.6h.6v6.4a1.2 1.2 0 0 0 2.4 0V7.6a3 3 0 0 0-1.6-3z"></path></svg></span>
            <span class="dev__txt"><span class="dev__name">Earbuds</span><span class="dev__sub" data-sub>Connected</span></span>
            <span class="dev__pct"><svg class="bolt" viewBox="0 0 12 16" aria-hidden="true"><path pathLength="1" d="M7.2 1.2 2.4 9h3.8l-1.4 5.8L9.6 7H5.8z"></path></svg><span class="roll" data-pct></span><span class="pct">%</span></span>
            <span class="batt" aria-hidden="true"><span class="batt__in"><span class="batt__fill" data-fill><span class="batt__sheen" data-sheen></span><svg class="batt__wave" viewBox="0 0 6 22" preserveAspectRatio="none"><path data-wave></path></svg></span></span><span class="batt__nub"></span></span>
          </button>
          <div class="dev__more" data-more><div class="dev__more-in"><p data-left></p><p class="muted" data-note>Left and right in step</p></div></div>
        </li>

        <li class="dev" data-dev="watch">
          <button class="dev__main" type="button" aria-expanded="false">
            <span class="dev__ic" aria-hidden="true"><svg viewBox="0 0 24 24"><rect x="6" y="6.4" width="12" height="11.2" rx="3"></rect><path d="M8.6 6.4 9.4 2.8h5.2l.8 3.6M8.6 17.6l.8 3.6h5.2l.8-3.6"></path><path d="M12 9.6V12l1.6 1"></path></svg></span>
            <span class="dev__txt"><span class="dev__name">Watch</span><span class="dev__sub" data-sub>On battery</span></span>
            <span class="dev__pct"><svg class="bolt" viewBox="0 0 12 16" aria-hidden="true"><path pathLength="1" d="M7.2 1.2 2.4 9h3.8l-1.4 5.8L9.6 7H5.8z"></path></svg><span class="roll" data-pct></span><span class="pct">%</span></span>
            <span class="batt" aria-hidden="true"><span class="batt__in"><span class="batt__fill" data-fill><span class="batt__sheen" data-sheen></span><svg class="batt__wave" viewBox="0 0 6 22" preserveAspectRatio="none"><path data-wave></path></svg></span></span><span class="batt__nub"></span></span>
          </button>
          <div class="dev__more" data-more><div class="dev__more-in"><p data-left></p><p class="muted" data-note>Workout mode off</p></div></div>
        </li>

        <li class="dev" data-dev="case">
          <button class="dev__main" type="button" aria-expanded="false">
            <span class="dev__ic" aria-hidden="true"><svg viewBox="0 0 24 24"><rect x="4" y="7" width="16" height="11.6" rx="4.2"></rect><path d="M4.4 11.2h15.2"></path><path d="M11 14.2h2"></path></svg></span>
            <span class="dev__txt"><span class="dev__name">Earbuds case</span><span class="dev__sub" data-sub>On battery</span></span>
            <span class="dev__pct"><svg class="bolt" viewBox="0 0 12 16" aria-hidden="true"><path pathLength="1" d="M7.2 1.2 2.4 9h3.8l-1.4 5.8L9.6 7H5.8z"></path></svg><span class="roll" data-pct></span><span class="pct">%</span></span>
            <span class="batt" aria-hidden="true"><span class="batt__in"><span class="batt__fill" data-fill><span class="batt__sheen" data-sheen></span><svg class="batt__wave" viewBox="0 0 6 22" preserveAspectRatio="none"><path data-wave></path></svg></span></span><span class="batt__nub"></span></span>
          </button>
          <div class="dev__more" data-more><div class="dev__more-in"><p data-left></p><p class="muted" data-note>Charge the case soon</p></div></div>
        </li>
      </ul>

      <footer class="foot"><span data-foot>Updated just now</span></footer>
    </section>
    </div>
    <p class="sr" aria-live="polite" data-live></p>
  </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.

39 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 “Battery levels widget” 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 cool paper, a white card with a soft multi-layer shadow and a thread of light on its edge. At the top “Batteries” and the device count, then one row per device: the outlined icon in a grey tile, the name and the status, the percentage and a small battery with its nub. The liquid inside the battery fills from empty on a spring, overshoots the level by a little and comes back; its edge is a thin wave that always moves slightly and sloshes more when the level runs. The digits of the percentage roll one by one. The earbuds connect: their row slides in between the phone and the watch as it opens, the icon arrives turned and straightens, and the count at the top becomes “4 devices”. The earbuds start charging: the green bolt draws itself next to the number, the liquid turns green and a light climbs slowly through it while the charge rises to 100. The case, which charges them, drops below the limit: it turns red, the battery gives a single beat and the number shivers slightly, and the status says “Low battery”. Hovering a row, or tapping it, opens it underneath to say how much is left (“2 h 40 min left”, “Full in 14 min”) with one more line. On its own it repeats the tour: the earbuds connect, charge and leave.

How it works

A level that is a number

Each device has an object with its level: GSAP takes it to the new value with a back.out (the spring) and at every step paint() sets the liquid's width, rolls the percentage only when the whole number changes and checks the low limit.

The liquid edge

On the liquid's right edge sits a small SVG with a nine-point path recalculated every frame: two sines shifted in time. The amplitude starts as a hair and grows with the level's speed, measured as the difference between one frame and the next and smoothed.

Charging and draining

Charging switches on a class that changes the liquid's colour through a CSS variable, draws the bolt with stroke-dashoffset (autoRound off) and slides a light with background-position. Below the limit, the red class and a single beat, scale 1.12 there and back.

The row that opens

The detail under each row goes from height 0 to auto with GSAP; the text inside drops 6 pixels and fades in. It opens on hover, on tap and with the Tab key, and the first touch on the page stops the self-running tour.

Values to change

NameFileDefaultWhat it changes
PHONE_LEVELscript.js82The phone's charge, in percent.
WATCH_LEVELscript.js47The watch's charge, in percent.
CASE_LEVELscript.js23The earbuds case's charge, in percent.
BUDS_LEVELscript.js64The earbuds' charge when they connect, in percent.
LOW_LIMITscript.js20Below this percentage the battery turns red.
CHARGE_TIMEscript.js4.5How long the earbuds take to charge fully in the tour, in seconds.
SPRINGscript.js1.4How far the liquid overshoots the level before settling (0 = no spring).
SLOSHscript.js1How much the liquid's surface moves (0 = still).
LOOP_PAUSEscript.js1.8The pause at the end of the tour before it starts again, in seconds.

Try them in the Playground

When to use it

In the app or site of a brand selling earbuds, watches or accessories; on a product page that shows how long it lasts; in a dashboard that tracks devices (sensors, scooters, robots) and has to say which ones are running low.

On phones

The card takes the width with a margin and its spacing, tiles and rows also follow the height with clamp and vh; when the box is short the line at the bottom goes. The battery stays large enough to see the liquid. A tap opens a row, a second tap closes it.

With reduced motion

No springs, waves, climbing light or rolling digits: the batteries appear already filled to their level, the earbuds already connected and charging with the bolt drawn, the rows open without motion and the self-running tour does not start.

Pitfalls

  • The button's focus opened the row and the click straight after closed it again: the row opens on focus only for keyboard focus (:focus-visible).
  • The wavy liquid edge stayed visible with the level at zero or a hundred: it switches off below 0.6% and above 99.4%.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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