
Speeding marquee
Scroll, Text, Hover
The hero preview in a made-up site builder, on warm white: dragging the right edge of the window keeps the headline on its two lines, first by narrowing its letters along the variable font’s width axis, from wide to condensed and a little bolder, and only when that is not enough by getting smaller. Below, the Desktop, Tablet and Phone formats snap the preview on a short spring, and next to them the width in pixels, the wdth axis, the weight and the size are read out live.
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>
<!--
"Fluid headline resize" 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 fluid headline that narrows as you drag the preview's edge</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 preview of a made-up site builder: drag the right edge and the hero headline keeps fitting, first narrowing its letters, then its size -->
<section class="banco" data-banco aria-label="Lattice site builder, hero preview">
<header class="barra">
<span class="marchio">
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3 3.5h10M3 8h10M3 12.5h10M5.5 2v12M10.5 2v12"></path></svg>
Lattice
</span>
<span class="barra__pagina">Home <span class="barra__sep">/</span> Hero</span>
<span class="barra__px" aria-live="off"><span class="rullo" data-px>1280</span> px</span>
</header>
<div class="area" data-area>
<div class="cornice" data-cornice>
<div class="hero" data-hero>
<p class="occhiello">Spring launch</p>
<h1 class="titolo" data-titolo>
<span class="riga" data-riga>Every word</span>
<span class="riga" data-riga>fits the frame.</span>
</h1>
<span class="guida" data-guida aria-hidden="true"><i></i><i></i></span>
<p class="sotto">Type that breathes with every screen.</p>
<span class="cta" data-cta>Start building
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8h9M8.5 4l4 4-4 4"></path></svg>
</span>
</div>
<div class="maniglia" data-maniglia role="slider" tabindex="0" aria-label="Preview width" aria-valuemin="390" aria-valuemax="1280" aria-valuenow="1280">
<span class="maniglia__presa"></span>
</div>
</div>
</div>
<footer class="piede">
<div class="scelte" data-scelte role="group" aria-label="Breakpoints">
<span class="scelte__fondo" data-scelte-fondo aria-hidden="true"></span>
<button class="scelta" type="button" data-scelta data-larga="1280">
<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="1.5" y="3" width="13" height="8.5" rx="1.5"></rect><path d="M5.5 13.5h5"></path></svg>
<span>Desktop</span>
</button>
<button class="scelta" type="button" data-scelta data-larga="768">
<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="3" y="1.5" width="10" height="13" rx="1.6"></rect><path d="M7 12.5h2"></path></svg>
<span>Tablet</span>
</button>
<button class="scelta" type="button" data-scelta data-larga="390">
<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="4.5" y="1.5" width="7" height="13" rx="1.6"></rect><path d="M7.2 12.6h1.6"></path></svg>
<span>Phone</span>
</button>
</div>
<p class="assi" data-assi aria-hidden="true">
<span>wdth <b data-wdth>125</b></span>
<span>wght <b data-wght>560</b></span>
<span><b data-size>64</b> px</span>
</p>
</footer>
</section>
<span class="titolo misura" data-misura aria-hidden="true"></span>
<svg class="ghost" data-ghost viewBox="0 0 20 20" aria-hidden="true"><path d="M4 2.5v13.2l3.5-3.3 2.4 5.3 2.3-1-2.4-5.2 4.8-.2z"></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>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.
35 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 “Fluid headline resize” from Animorio and fit it into my siteWhen the fonts are ready the script measures the two lines at 100 pixels for every step of the wdth axis, from 75 to 125, with the weight that goes with that step, and keeps the widest line in a table: afterwards, on every frame, it only reads the table and measures nothing.
The line’s room is the preview width minus the margins. If the wide headline fits at the largest size, MAX_SIZE, it stays like that; if not, a bisection finds the letter width that makes it fit to the pixel; if even the narrowest letters are not enough, the headline gets as much smaller as needed.
Narrow letters look lighter: the weight grows by INK_GAIN for every point of width lost, so the line keeps the same blackness. Weight and width live in two CSS variables inside font-variation-settings.
The preview is centred, so moving the right edge by one pixel changes the width by two: the script doubles the movement and keeps it in virtual pixels, from 390 to 1280, which do not change when the page is resized. Past the ends the movement counts half, and the drawing shows thirty per cent of it: the rubber band.
Desktop, Tablet and Phone carry their width in data-larga; GSAP takes the state there with back.out(SNAP_BOUNCE) and redraws headline, blue line and numbers at every step. The white background of the pills slides under the one for the format the preview is in.
| Name | File | Default | What it changes |
|---|---|---|---|
WDTH_MAX | script.js | 125 | The letter width when the preview is wide (75 to 125). |
WDTH_MIN | script.js | 75 | The narrowest width before the headline starts getting smaller. |
WEIGHT | script.js | 560 | The headline’s weight with the widest letters. |
INK_GAIN | script.js | 1.6 | How much weight the letters gain for every point of width lost. |
MAX_SIZE | script.js | 72 | The headline’s largest size, in pixels. |
MIN_FRAME | script.js | 0.34 | The narrowest preview width, as a share of the canvas. |
SNAP_BOUNCE | script.js | 1.3 | How much the preview bounces when a format is chosen (0 means no bounce). |
AUTO_PILOT | script.js | 1.2 | After how many seconds the drawn pointer starts (0 means never). |
For the hero of a landing page that wants to show its headline holds up on every screen, for the page of a site builder, an editor or a type foundry explaining fluid typography, or for a tutorial on variable fonts.
The same animation with adapted sizes: the window is measured on the screen’s width and height, the format pills show only their icon and the handle is dragged with a finger.
No drawn pointer, no spring and no entrance: the window fades in, the handle and the formats change the preview at once, and the headline keeps fitting its lines.
GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.
Compressed with gzip, the three demo files weigh 7.2 KB; the libraries: GSAP 28 KB.
Tested on 29 October 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.