Skip to content
animorio
IT
All components

Scroll pill nav

Navigation, Scroll, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.6 KBGSAP 28 KBLenis 5.3 KBFreeDownload the zip

Scroll inside the preview

The navigation bar of a SaaS site, as wide as the page at the top: scrolling down it lifts off the edge and gathers on a short spring into a frosted glass pill in the middle, with the same links. The wordmark folds away behind the symbol, Get started shortens to Start, a hairline border and a shadow that grows as you read appear; back at the top it opens out wide. A soft pill slides under the link you point at. Morphin style, clean, on the palest grey.

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>
<!--
  "Scroll pill nav" 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 nav that shrinks into a pill on scroll</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>
  <!-- the header of a docs tool: wide across the page at the top; scrolling down it lifts off the edge and gathers on a
       spring into a centred frosted pill, the wordmark folds away behind the symbol and the button shortens to Start.
       A soft pill slides under the link you point at. Scrolling back to the top it opens out again. -->
  <header class="nav" data-nav>
    <div class="nav__shape" data-shape>
      <div class="nav__inner">
        <a class="brand" href="#" aria-label="Docwell, home">
          <svg class="brand__mark" data-mark viewBox="0 0 24 24" aria-hidden="true">
            <rect x="3.5" y="3.5" width="17" height="17" rx="5.5"></rect>
            <path d="M8.5 9h7M8.5 12h7M8.5 15h4"></path>
          </svg>
          <span class="brand__word" data-word><span class="brand__text" data-word-text>Docwell</span></span>
        </a>

        <nav class="links" data-links aria-label="Main">
          <span class="links__hl" data-hl aria-hidden="true"></span>
          <a class="link is-active" href="#" data-link aria-current="page">Product</a>
          <a class="link" href="#" data-link>Pricing</a>
          <a class="link link--wide" href="#" data-link>Customers</a>
          <a class="link link--wide" href="#" data-link>Docs</a>
        </nav>

        <a class="cta" href="#" data-cta>
          <span class="cta__labels" data-labels>
            <span class="cta__label cta__label--long" data-long>Get started</span>
            <span class="cta__label cta__label--short" data-short aria-hidden="true">Start</span>
          </span>
          <svg class="cta__arrow" viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8h8.5M8.8 4.6 12.2 8l-3.4 3.4"></path></svg>
        </a>
      </div>
    </div>
  </header>

  <main class="page">
    <section class="hero">
      <p class="hero__tag">Docwell for teams</p>
      <h1 class="hero__title">Docs your team actually reads.</h1>
      <p class="hero__sub">Write once, link everywhere. Docwell keeps specs, guides and decisions in one calm place.</p>
      <div class="hero__ctas"><span class="ghost ghost--dark"></span><span class="ghost"></span></div>
      <p class="hero__hint" data-hint>Scroll down</p>
    </section>

    <section class="block">
      <div class="lines"><span style="--w: 42%"></span><span style="--w: 76%"></span><span style="--w: 64%"></span></div>
      <div class="cards">
        <div class="card"><span class="card__icon"></span><span class="card__line" style="--w: 70%"></span><span class="card__line" style="--w: 90%"></span><span class="card__line" style="--w: 55%"></span></div>
        <div class="card"><span class="card__icon"></span><span class="card__line" style="--w: 60%"></span><span class="card__line" style="--w: 85%"></span><span class="card__line" style="--w: 70%"></span></div>
        <div class="card"><span class="card__icon"></span><span class="card__line" style="--w: 75%"></span><span class="card__line" style="--w: 50%"></span><span class="card__line" style="--w: 80%"></span></div>
      </div>
    </section>

    <section class="block">
      <div class="lines"><span style="--w: 36%"></span><span style="--w: 70%"></span></div>
      <div class="panel"><span class="panel__bar"></span><span class="panel__row" style="--w: 82%"></span><span class="panel__row" style="--w: 64%"></span><span class="panel__row" style="--w: 74%"></span><span class="panel__row" style="--w: 48%"></span></div>
    </section>

    <section class="block block--end">
      <p class="end__title">Start writing in two minutes.</p>
      <div class="lines lines--centre"><span style="--w: 58%"></span></div>
    </section>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/lenis@1.3.26/dist/lenis.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.

28 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 “Scroll pill nav” 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

At the top of the page of Docwell, an invented docs tool for teams, the header is as wide as the page: on the left the black symbol and the name, in the middle Product, Pricing, Customers and Docs, on the right the black Get started button with its drawn arrow. Below, the headline “Docs your team actually reads.” and the page made of grey lines and cards. Scrolling down a few lines, the header lifts off the edge and gathers on a short spring into a pill in the middle, a little shorter and with a pixel of bounce: the name folds away behind the symbol as it fades, the symbol leans with the speed of the spring and straightens up, Get started rolls into Start, the links close in, the background turns to frosted glass and a hairline border appears with a soft shadow that keeps growing as you scroll. Back at the top everything opens out wide with the same spring. Pointing at the links, a soft grey pill slides under the one you point at, squashing a little as it lands, and goes back to Product when the pointer leaves; when nobody points, once the bar is a pill the grey pill walks from link to link by itself. The button squashes when pressed and comes back with a bounce.

How it works

One shape and one number

The header is a single element, and everything that changes (width, height, place, corners, padding) is a mix between the wide size and the pill size, driven by a number p from 0 to 1. So the spring’s bounce is the bounce of the whole bar, and no piece arrives before the others.

The spring on GSAP’s ticker

Scrolling only decides where p should go (0 above SHRINK_AT pixels, 1 below); every frame a spring with stiffness and damping takes it there, in two half steps to stay stable. The spring’s speed also tilts the symbol.

Real sizes, not guesses

The width of the pill is the sum of what it holds: the symbol, the visible links, the short button and the padding. It is measured again on every resize, and on a phone only two links stay.

Glass from the CSS

Background, blur, border and shadow read the --p and --s variables in CSS with calc(): the script writes just two numbers, and the glass, the hairline and the shadow growing with the scroll work themselves out.

Values to change

NameFileDefaultWhat it changes
SHRINK_ATscript.js80How many pixels down the page the bar becomes a pill.
STIFFNESSscript.js320How stiff the bar’s spring is.
DAMPINGscript.js0.72How much the spring is held back (1 = no bounce).
PILL_HEIGHTscript.js52The height of the pill, in pixels.
PILL_TOPscript.js12The gap between the pill and the top edge, in pixels.
HIGHLIGHTscript.js0.38How many seconds the grey pill takes to slide under a link.
TOURscript.js2.1When nobody points, every how many seconds the grey pill moves to the next link (0 = never).

Try them in the Playground

When to use it

For the header of a product site, a SaaS tool or a landing page: wide and calm at the top, where there is room, and gathered into a pill while you read, so it takes little space and stays within reach.

On phones

The same spring and the same pill: two links stay, Product and Pricing, the wordmark folds away the same way and the pill sits 8 pixels from the edge, at most the screen width minus 16 pixels. The grey pill moves on tap.

With reduced motion

No spring and no smooth scrolling: the bar switches from wide to pill and back at once, the symbol does not lean and the grey pill jumps under the link without sliding.

Pitfalls

  • If width, height and corners each had their own tween, halfway the bar would be a crooked shape: everything comes from one number.
  • The corners round with the value without the bounce, otherwise in the bounce the wide bar would have round corners for a moment.
  • The width of the pill is measured after the fonts load (document.fonts.ready): with the fallback font the links are narrower and the pill would cut them.
  • A spring in a single step, at 60 frames and high stiffness, can run away: two half steps per frame keep it steady.

Libraries

GSAP 3.15.0, Lenis 1.3.26, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 26 October 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