Skip to content
animorio
IT
All components

BMI calculator

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

The body mass index calculator of a health app. Drag height and weight and the number counts to its new value while the needle moves along a four-zone arc, swinging before it settles; number and zone name take the colour of where they are. Below, the healthy weight range for that height. In centimetres and kilos, or feet and pounds.

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>
<!--
  "BMI calculator" 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>BMI calculator</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 BMI calculator for a health app: drag height and weight, the needle swings along a four-zone arc,
         the number counts and takes the colour of its zone; metric or imperial -->
    <section class="bm" data-bm aria-label="BMI calculator">
      <header class="bm__head">
        <h2 class="bm__title">Body mass index</h2>
        <div class="bm__units" data-units role="radiogroup" aria-label="Units">
          <span class="bm__thumb" data-thumb aria-hidden="true"></span>
          <button type="button" role="radio" aria-checked="true" data-unit="metric">cm · kg</button>
          <button type="button" role="radio" aria-checked="false" tabindex="-1" data-unit="imperial">ft · lb</button>
        </div>
      </header>

      <div class="bm__gauge">
        <svg viewBox="0 0 240 132" aria-hidden="true">
          <g data-zones></g>
          <g data-marks class="bm__marks"></g>
          <g data-needle><line class="bm__needle" x1="120" y1="66" x2="120" y2="36"></line></g>
        </svg>
        <div class="bm__read">
          <output class="bm__value" data-value>22.9</output>
          <span class="bm__roll bm__zone"><span data-zone>Healthy</span></span>
        </div>
      </div>

      <label class="bm__field">
        <span class="bm__name">Height</span><output class="bm__num" data-hout>175 cm</output>
        <input type="range" min="140" max="205" step="1" value="175" data-h>
      </label>
      <label class="bm__field">
        <span class="bm__name">Weight</span><output class="bm__num" data-wout>70 kg</output>
        <input type="range" min="40" max="140" step="1" value="70" data-w>
      </label>

      <p class="bm__range" data-range aria-live="polite"></p>
    </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.

23 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 “BMI calculator” 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, a light card: “Body mass index” and, on the right, the unit switch. In the middle a half-circle arc split in four pieces, blue, green, amber and coral, with the boundary values written outside (18.5, 25, 30); a short dark needle runs just inside the arc and in the middle sits the big number, 22.9, with its zone, “Healthy”. Below, two sliders: Height and Weight, each with its value. Drag the weight and the number counts at once to the new value, the needle arrives a moment later, overshoots and comes back once or twice before settling; on crossing into another zone its piece of arc lights up, the others dim, the name rolls and number and name change colour. At the foot a line gives the healthy weight for that height. Switch to feet and pounds and the white thumb slides, the values change unit and the index stays the same.

How it works

The arc in pieces

The scale runs from 15 to 40 over 180 degrees. Each zone is an arc path worked out from its two angles, with just over a degree of gap between pieces; the boundary values are text placed on the same angle, further out.

Quick number, lazy needle

Two tweens on the same object: the value shown arrives in a third of a second, the needle’s angle in just over a second on an elastic. The delay is what makes the needle feel like something with weight.

The needle turns in the attribute

The rotation is written into the transform attribute with the pivot in viewBox coordinates (rotate(degrees 120 122)): on an SVG group transformOrigin would spin around the bounding box.

Units are only how it is written

The two sliders always work in centimetres and kilos; feet, inches and pounds are worked out when the values are written. Changing units moves neither the sliders nor the needle.

Values to change

NameFileDefaultWhat it changes
HEIGHTscript.js175The starting height, in centimetres.
WEIGHTscript.js70The starting weight, in kilos.
SWINGscript.js1How much the needle swings before it stops: 0.3 = hardly, 2 = a lot.
IMPERIALscript.jsfalsetrue = start in feet and pounds instead of centimetres and kilos.
LOOPscript.jstrueLeft alone, the demo’s pointer drags weight and height and switches units.

Try them in the Playground

When to use it

In the app of a nutrition practice, a gym, a connected scale or a health insurer; on a doctor’s site. The same needle on a zoned arc suits any value with thresholds: blood pressure, a connection’s speed, a score.

On phones

The same card, as wide as the screen: the two sliders have a 22-pixel thumb and do not scroll the page while dragged; the arc scales in proportion and everything stays inside the preview box.

With reduced motion

The number and the needle go straight to the new value, with no counting or swinging; zone and colours change at once. The demo does not move by itself.

Pitfalls

  • The thresholds are the World Health Organization’s for adults (18.5, 25 and 30). BMI cannot tell muscle from fat and does not apply to children, athletes or pregnancy: always put a line beside the number saying so, and it is not a diagnosis.
  • Below 15 and above 40 the needle stops at the end of the scale, but the number written stays the true one.
  • A long needle from a hub ran over the number in the middle: the needle is short and stays near the arc, leaving the centre to the number.
  • The filled part of the slider track is a CSS variable updated by the script: Chromium and Safari have no “progress” part of the track.
  • With a very elastic needle and a value at the end of the scale the needle briefly passes the arc: the svg must not clip it (visible overflow).

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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