Skip to content
animorio
IT
All components

Recipe servings card

Cards, HoverGSAP, CSS onlyMediumCompressed weight: Demo 7.3 KBGSAP 28 KBFreeDownload the zip

The card of a recipe, with a real photo of the dish at the top, on warm white: changing the servings with plus and minus, every amount rolls to its new value, fractions included (½, 1, 1½), units grow when needed (ml to l, g to kg) and the cooking time follows, with its clock hand turning. Ticking an ingredient fills its box and a line strikes it through; the button adds everything to the shopping list with a check that draws itself.

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>
<!--
  "Recipe servings 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>The recipe card whose servings recalculate the ingredients</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" data-stage>
    <!-- the card of a recipe: the servings stepper scales every ingredient, the amounts roll to their new value
         (fractions included), the units change when they grow (ml to l, g to kg) and the cooking time follows;
         ticking an ingredient strikes its row through -->
    <article class="recipe" data-card aria-label="Lemon and pesto pasta">
      <figure class="dish" aria-hidden="true">
        <img class="dish__img" data-plate src="piatto.webp" alt="" width="1024" height="683" decoding="async">
        <span class="dish__tag">Vegetarian</span>
      </figure>

      <header class="recipe__head">
        <div class="recipe__titles">
          <p class="recipe__brand" data-brand>Sorrelby</p>
          <h1 class="recipe__title">Lemon &amp; pesto pasta</h1>
        </div>
        <p class="recipe__time" aria-label="Cooking time">
          <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="13" r="8"/><path d="M12 9v4.4l2.8 1.8" data-hand/><path d="M10 3h4"/></svg>
          <span class="roll" data-time><span class="roll__in">25</span></span><span class="unit">min</span>
        </p>
      </header>

      <div class="serve">
        <span class="serve__label">Servings</span>
        <div class="stepper" role="group" aria-label="Servings">
          <button class="stepper__btn" type="button" data-minus aria-label="Fewer servings"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 12h12"/></svg></button>
          <span class="stepper__num roll" data-servings aria-live="polite"><span class="roll__in">2</span></span>
          <button class="stepper__btn" type="button" data-plus aria-label="More servings"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 12h12M12 6v12"/></svg></button>
        </div>
        <span class="serve__note" data-note>As written</span>
      </div>

      <ul class="ingredients" data-list aria-label="Ingredients"></ul>

      <footer class="recipe__foot">
        <span class="foot__left" data-left>5 to get</span>
        <button class="foot__btn" type="button" data-shop>
          <span class="foot__a">Add to shopping list</span>
          <span class="foot__b" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M5.5 12.6 9.8 16.8 18.6 7.6" data-shopcheck/></svg>Added</span>
        </button>
      </footer>
    </article>

    <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"/></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.

25 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 “Recipe servings 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 a warm white sits the card of a recipe from Sorrelby, an invented cooking site: at the top a real photo of the dish, a pistachio pesto pasta with lemon zest and two basil leaves on a white plate, on a grey wooden table with a linen napkin, scattered pistachios and two lemons; then the title Lemon & pesto pasta and beside it the cooking time with its clock. Below, Servings with a plus and a minus and the note «As written», and five ingredients with their box, the name and the amount aligned right: pasta, pasta water, lemon, pistachio pesto and parmesan. Pressing plus, every amount rolls to its new value, one row after another, upwards when it grows and downwards when it shrinks: the lemon goes from ½ to 1 and 1½, the pesto from 2½ to 3¾ tablespoons, and at eight servings the water goes from 875 ml to 1 l and the pasta from 875 g to 1 kg, and a unit that changes arrives narrow on the wdth axis, in orange, and widens. The note says how much the recipe has been scaled, the cooking time rolls and the clock hand turns, the photo of the dish breathes a little. Tapping a box squashes it and fills it with orange on a bounce, the check draws itself, a line strikes the name through and the row nudges two pixels; at the bottom the count of what is left rolls. Add to shopping list squashes, comes back on an elastic and turns orange with «Added» and its check. A drawn pointer goes up to eight servings, ticks three ingredients, adds to the list, goes back to two and starts again; it also really works, with mouse, touch and keyboard.

How it works

Amounts per serving

Each ingredient knows how much it takes for one serving and what kind it is: a weight, a volume, a spoon or a piece. A single function writes the value: weights move to kilograms from a thousand grams, volumes to litres from a thousand millilitres, spoons and pieces are written in quarters, with the ¼, ½ and ¾ characters made with String.fromCharCode.

The rolling number

Each amount sits in a small window with a mask that fades top and bottom. When it changes, the old value becomes an absolutely positioned copy that leaves, and the new one arrives from the opposite side with back.out: upwards if the number grows, downwards if it shrinks.

The changing unit

If the written unit differs from the new one, the label arrives narrow on the variable font’s wdth axis (70), orange and transparent, and widens to 100 with a small bounce; then it goes back to grey. The rows start forty milliseconds apart.

Tick and strike

The box squashes to 0.82 and comes back with back.out(3) as it fills with orange; the check is a stroke with a strokeDasharray that draws itself, and the line striking the name is an element going from scaleX 0 to 1 from the left. Unticking pulls the line back to the right.

The autopilot

A drawn pointer presses plus up to eight servings, ticks three ingredients, adds to the list and goes back to two, reading the real position of the buttons every time. At the first real touch it stops, and it starts again after eight quiet seconds.

The dish photo

At the top an img with object-fit cover sits in a strip clamp(54px, 15vh, 128px) tall: the photo is a 1024-pixel CC0 webp and is swapped in the HTML without touching the script. The script keeps it at scale 1.04, so when it breathes with the servings (from 1.04 to 1.065 or 1.015 and back) its edges never show; a light dark veil at the top keeps the Vegetarian tag readable on the bright photo.

Values to change

NameFileDefaultWhat it changes
RECIPEscript.jsLemon & pesto pastaThe recipe’s name, written under the brand.
BASEscript.js2The servings the recipe is written for.
MAXscript.js8The largest number of servings.
ACCENTscript.js#d0632fThe colour of the ticked box, of the changing units and of the button once added.
ROLLscript.js0.42The seconds an amount takes to roll to its new value.
PAUSEscript.js0.7The seconds the drawn pointer waits between one gesture and the next.

Try them in the Playground

When to use it

For a food blog, a restaurant site that shares its recipes, a grocery or meal-planning app, the page of a food product with a suggested recipe.

On phones

The card takes the screen’s width and is measured on the height too: the dish picture and the ingredient rows get shorter with the window’s height, so everything stays inside the box; under 360 pixels the scale note goes and the margins tighten. A tap does what a click does.

With reduced motion

No rolling, no bounces and no turning hand: the numbers change with a fade, the box fills and the line strikes at once, and the drawn pointer stays hidden.

Pitfalls

  • The ¼, ½ and ¾ fractions typed by hand in the code can turn into other characters on the way through tools: they are made with String.fromCharCode(188, 189, 190).
  • Two serving changes in a row left the old copy under the new one: before every roll the leftover copies are removed and the running tween is stopped.
  • The amount and the unit sit in two separate elements: if the unit stays the same it is not touched, so the narrow-to-wide effect only shows when it really changes.
  • The photo breathes with a scale: below 1 its edges would show inside the strip, so it starts at 1.04, and the transform origin matches object-position (50% 54%), on the plate.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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