Skip to content
animorio
IT
Back to the library

Nutrition facts card

Text, HoverGSAP, CSS onlyMediumCompressed weight: Demo 5.4 KBGSAP 28 KBFreeDownload the zip

A dish’s nutrition label, redone as a dark card: changing the portions makes every figure count to its new value, the calories gain weight, and under each line a thin rule says how much of the day it covers, warmer when it passes it. Moving over a line lights its piece in the macronutrient bar.

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>
<!--
  "Nutrition facts card" 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>Nutrition facts card</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 nutrition facts of a dish: change the portions and every figure counts to its new value,
         the calories gain weight, and the share of the day on each line grows towards its limit -->
    <section class="nf" data-nf aria-label="Nutrition facts">
      <header class="nf__head">
        <span class="nf__title">Nutrition</span>
        <div class="nf__qty" role="group" aria-label="Portions">
          <button type="button" data-less aria-label="One portion less"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.500 8h9"></path></svg></button>
          <span class="nf__n" aria-live="polite"><span data-n></span></span>
          <button type="button" data-more aria-label="One portion more"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.500 8h9M8 3.500v9"></path></svg></button>
        </div>
      </header>

      <p class="nf__read">
        <b class="nf__kcal" data-kcal>0</b>
        <span class="nf__unit">kcal<br><span data-day></span></span>
      </p>

      <div class="nf__bar" data-bar aria-hidden="true"></div>
      <div class="nf__rows" data-rows></div>
    </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.

18 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 “Nutrition facts card” 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 dark card: at the top “Nutrition” and the portions stepper; below, the calories in large heavy figures with “kcal” and the share of a day, closed by a thick rule as on real labels; then a bar in three pieces, carbohydrate, protein and fat, as wide as the calories they bring; then four rows: Carbohydrate, Protein, Fat, Salt, with grams and the percentage of a day’s reference intake, and under each a thin yellow rule as long as that percentage. On opening the numbers count from zero and the bar opens from the left. Pressing plus, the portions roll and all the numbers count together without overshooting, the calories get heavier and the bar’s three pieces jolt one after the other; at the third portion protein passes 100%, and its rule and percentage turn orange. Moving over a line lights its piece of the bar in yellow.

How it works

One number, the portions shown

A single number is animated, the portions shown, and every figure on the label is that number times its value: calories, grams, percentages and rule lengths always stay consistent, even mid-count.

The calories’ weight

The calories’ wght axis follows the portions, from 670 to 900: more portions, more black. The scale gives a small bounce, the number does not.

The bar in calories, not grams

The three pieces are flex items as wide as each macronutrient’s calories (4 per gram of carbohydrate and protein, 9 for fat): the proportion does not change with the portions, so the bar jolts but is not redrawn.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#ffd43bThe colour of the share of the day and of the chosen piece.
OVERscript.js#ff7a59The colour of a line that passes the whole day.
KCALscript.js520The calories in one portion.
CARBSscript.js62The carbohydrate in one portion, in grams.
PROTEINscript.js24The protein in one portion, in grams.
FATscript.js18The fat in one portion, in grams.
SALTscript.js1.6The salt in one portion, in grams.
COUNTscript.js0.6How many seconds the numbers take to reach the new value.
HOLDscript.js1.5On its own: how many seconds it stops on each step.
LOOPscript.jstrueLeft alone, a pointer adds portions and looks at two lines.

Try them in the Playground

When to use it

On a dish’s page in a food delivery or recipe app, in a food diary, on the site of something to eat; and wherever a table of numbers depends on a quantity: a project’s materials, a recipe’s amounts, a quote.

On phones

The same card: tapping a row lights its piece of the bar, tapping it again turns it off. The calories and the rows shrink with the window’s height.

With reduced motion

No counting and no jolts: on changing the portions, numbers, weight and rules are already at the new value.

Pitfalls

  • The dish’s values are made up; the day’s reference amounts (2000 kcal, 260 g carbohydrate, 50 g protein, 70 g fat, 6 g salt) are those of European labels for an average adult.
  • A real label follows legal rules on lines, order and rounding, different from country to country: this is a card for an app, not a label to print on a pack.
  • Passing the day is not told by colour alone: the percentage is written, and it goes over 100.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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