
The elastic button
Buttons, Hover, Text
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.
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 & 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>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
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 siteEach 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.
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.
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.
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.
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.
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.
| Name | File | Default | What it changes |
|---|---|---|---|
RECIPE | script.js | Lemon & pesto pasta | The recipe’s name, written under the brand. |
BASE | script.js | 2 | The servings the recipe is written for. |
MAX | script.js | 8 | The largest number of servings. |
ACCENT | script.js | #d0632f | The colour of the ticked box, of the changing units and of the button once added. |
ROLL | script.js | 0.42 | The seconds an amount takes to roll to its new value. |
PAUSE | script.js | 0.7 | The seconds the drawn pointer waits between one gesture and the next. |
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.
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.
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.
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.
Tested on 5 November 2026
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.
Support Animorio
Animorio stays free thanks to the people who support it. If you like, buy us a coffee: it helps us make the next animations.
You asked for
We made it for you: it’s in the library, with the preview, the Playground and the code to copy.
An animation you can’t find, or a site to take apart in the journal: tell us which. We pick the next ones from here.
With your account’s email and password.
or with your email
You’re signed in as .
With your account, you can download the zip of every animation and every pack, for free.