Skip to content
animorio
IT
Back to the library

Pills in the headline

Text, Hover, ImagesCSS only, GSAPEasyCompressed weight: Demo 3.1 KBGSAP 28 KBFreeDownload the zip

A large headline with three pills between its words, each holding a photo: they open one after the other pushing the text apart, and passing over them they widen further, lighten and show where they lead.

Rebuilt from scratch studying marimba.design by Myranda Wicks: the idea is theirs; code, copy and images are ours. Read how it’s made

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>
<!--
  "Pills in the headline" 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="it">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Le pillole nel titolo</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/standard.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/instrument-serif@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="pagina">
    <p class="nota" data-nota>Nel titolo si aprono tre pillole con dentro una foto; passandoci sopra si allargano, si schiariscono e dicono dove portano.</p>
    <h1 class="titolo" data-titolo>
      Disegniamo <a class="pillola" href="#" data-pillola style="--velo: #DCEFF8"><span class="pillola__quadro"><img src="orto.webp" alt="" width="900" height="600" decoding="async"></span><span class="pillola__nome">Chi siamo</span></a> orti e giardini che si guardano <a class="pillola" href="#" data-pillola style="--velo: #FBE3EC"><span class="pillola__quadro"><img src="tulipani.webp" alt="" width="900" height="600" decoding="async"></span><span class="pillola__nome">Lavori</span></a> anche dalla finestra <a class="pillola" href="#" data-pillola style="--velo: #E9F4D8"><span class="pillola__quadro"><img src="davanzale.webp" alt="" width="900" height="574" decoding="async"></span><span class="pillola__nome">Scrivici</span></a> di casa.
    </h1>
  </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.

16 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 “Pills in the headline” 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

A large serif headline over three lines: between its words sit three pills with a small real photo inside: a kitchen garden of wooden raised beds in the sun, a bed of peach tulips, a white window with two potted plants on the sill. On opening the pills are zero wide and open one after the other, and the line reopens to make room for the picture. Inside each pill the photo slowly drifts back and forth. Passing the mouse over a pill, it widens further and pushes the words, a pastel veil lightens the photo and the link’s name appears: Chi siamo, Lavori, Scrivici (about, work, contact).

How it works

A pill is a word

Each pill is an inline-block link inside the headline, 0.8em tall with a full border-radius: it is measured on the headline’s size, so it follows the text at any size. It starts with width 0 and zero margins: the line is set as if it were not there.

Opening by pushing

Once the font has loaded, the headline gets a class and the pills go to width 1.45em with a 1.2-second transition, each 180 milliseconds after the other. Animating width means reflowing every frame, but these are three elements in one line: the text reflowing is exactly what makes the effect.

The veil and the name

On mouse over the width goes to 2.3em, an ::after with a pastel in mix-blend-mode: lighten, at 84%, brightens the photo while letting it show through, and the name, in another typeface, rises from scale 0.92. A single pointermove listener decides what is under the pointer; keyboard focus does the same.

No delays afterwards

The staggered delay is only for the opening: once it is over, the script resets each pill’s --i variable, so the response to the mouse is immediate. The photo inside, an img with object-fit: cover enlarged by 12%, drifts with a 5-second yoyo tween, slightly longer for each pill: the enlargement’s margin covers the drift, so the edges never show.

Values to change

NameFileDefaultWhat it changes
--largostyle.css1.45em, 2.3emThe pill’s width when open and on mouse over, in the headline’s em.
--veloindex.htmlper pillolaThe pastel that lightens the photo on mouse over.
APREscript.js400The milliseconds before the pills start opening.

Try them in the Playground

When to use it

For the headline of a home page or a portfolio that wants to lead somewhere at once: the pills are links, and they can hold photos, videos or drawings.

On phones

The pills are measured on the headline, so they shrink with it; with a finger they light up on touch and stay lit for just over a second, long enough to widen, then return as they were.

With reduced motion

The pills are already open and do not widen: on mouse over only the veil and the name change, with a short fade, and the photo inside stays still.

Pitfalls

  • Opening the pills before the font has loaded reflows the headline twice: wait for document.fonts.load, then add the class.
  • If the staggered delay stays after the opening, the third pill answers the mouse 360 milliseconds late.
  • The veil with mix-blend-mode: lighten needs a light colour: a dark one lightens nothing.
  • A zero-width link reachable by Tab is an invisible focus: here the pill opens anyway, and on focus it lights up as on mouse over.
  • The photo inside the pill has an empty alt: the link’s name is already the label that appears on mouse over, and a long alt would stretch it for screen-reader users. No loading=lazy: inside a zero-width pill the browser would put the photo off and the pill would open empty.

Libraries

GSAP 3.15.0, Instrument Serif 5.3.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 6 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: Done

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