Skip to content
animorio
IT
All components

Segmented control

Pickers, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.6 KBGSAP 28 KBFreeDownload the zip

The visitors card of an analytics app, clean on white: on top sits a Day, Week, Month and Year segmented control. Picking a period, the white pill slides towards the segment and stretches, its leading edge leaving first and settling one pixel too far, the chosen label gains weight, the big number rolls to the new digits like an odometer and the bars of the small chart dip and rise again one after the other.

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>
<!--
  "Segmented control" 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 segmented control with a sliding pill</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">
    <!-- the visitors card of an analytics app: a Day / Week / Month / Year segmented control whose white pill
         stretches towards the chosen period, the big number rolls to the new figure and the bars rise again -->
    <section class="card" data-card aria-label="Plotwise visitors">
      <header class="card__head">
        <span class="brand">
          <svg class="brand__mark" viewBox="0 0 20 20" aria-hidden="true"><path d="M3.5 15.5 8 9.5l3.2 3 5.3-7"></path><path d="M3.5 4.5v11h13"></path></svg>
          <span class="brand__name">Plotwise</span>
        </span>
        <span class="card__site">northpine.studio</span>
      </header>

      <div class="seg" role="radiogroup" aria-label="Period" data-seg>
        <span class="seg__hover" data-hover aria-hidden="true"></span>
        <span class="seg__pill" data-pill aria-hidden="true"><span class="seg__shine"></span></span>
        <button class="seg__opt" type="button" role="radio" aria-checked="true" tabindex="0" data-opt="0">Day</button>
        <button class="seg__opt" type="button" role="radio" aria-checked="false" tabindex="-1" data-opt="1">Week</button>
        <button class="seg__opt" type="button" role="radio" aria-checked="false" tabindex="-1" data-opt="2">Month</button>
        <button class="seg__opt" type="button" role="radio" aria-checked="false" tabindex="-1" data-opt="3">Year</button>
      </div>

      <div class="stat">
        <p class="stat__label"><span data-label>Visitors today</span></p>
        <div class="stat__row">
          <p class="stat__num" data-num aria-live="polite"></p>
          <span class="badge" data-badge>
            <svg class="badge__arrow" viewBox="0 0 12 12" aria-hidden="true"><path d="M6 9.5v-7M2.8 5.6 6 2.4l3.2 3.2"></path></svg>
            <span data-delta>12.4%</span>
          </span>
        </div>
        <p class="stat__note" data-note>vs. yesterday</p>
      </div>

      <div class="chart" data-chart aria-hidden="true">
        <div class="chart__grid"><span></span><span></span><span></span></div>
        <div class="chart__bars" data-bars></div>
      </div>
      <div class="chart__axis" aria-hidden="true"><span data-from>00:00</span><span data-to>Now</span></div>
    </section>

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

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 “Segmented control” 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 very light grey background sits the white visitors card of Plotwise, an invented analytics app, for a studio’s site, northpine.studio. At the top a grey track with four segments, Day, Week, Month and Year, and over the chosen one a white pill with a soft shadow; below, Visitors today, the big number, an indigo badge with the arrow and the growth, and a small chart of fourteen grey bars with the last one, now, in indigo. Picking another period the pill does not jump: the leading edge leaves first and goes one pixel too far, the trailing edge catches up, so the pill stretches as it slides and squeezes slightly in height, then settles exactly on the segment. The chosen label gains weight, the others lose it; the number rolls to the new digits like an odometer, the units last, and extra digits fade in; the bars dip and rise again one after the other with a small bounce, while the label, the comparison, the growth and the dates under the chart change. With the mouse over an unselected segment a light ghost pill appears and follows the pointer; pressing the one already chosen squeezes the pill and lets it go. A drawn pointer tries Week, Month, Year and goes back to Day; it also really works, with touch and the arrow keys.

How it works

Two edges instead of a position

The pill has no position but two edges, left and right, in an object GSAP animates; on every update they become a translateX and a width. The edge facing the new segment leaves at once, the one behind a moment later: the difference is the stretch, and STRETCH sets it.

One pixel too far

Both edges arrive one pixel past the goal, in the direction of travel, with power3.out; then a last half spring in sine.inOut puts them back exactly. Meanwhile the pill drops six per cent in height and comes back, like something stretching as it runs.

The weight of the label

The typeface is variable Mona Sans: each segment has a CSS variable --w inside font-variation-settings and GSAP takes it from 500 to 640 for the chosen one and back for the others, without the segments changing width.

Digits on a wheel

Each digit is a column of twenty numbers, 0 to 9 twice, in a window one line high. To go from one value to the next the column always scrolls forward, even a full turn if the digit stays the same, and the units run a little longer than the tens; at the end it quietly resets to the first turn.

Bars that breathe

The fourteen bars dip to a quarter of their height in a row and rise to the new values with back.out, staggered by BAR_STAGGER. The drawn pointer is a repeating timeline, and stops at the first real touch or key.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#4f46e5The colour of the current bar, the mark and the badge.
STRETCHscript.js1How much the pill stretches as it slides.
SLIDE_TIMEscript.js0.42The seconds the pill takes to reach the segment.
ROLL_TIMEscript.js0.9The seconds the digits take to roll to the new number.
BAR_STAGGERscript.js0.03The seconds between one bar and the next as they rise.
PAUSEscript.js1.6The seconds the autopilot stays on each period.

Try them in the Playground

When to use it

For picking a dashboard’s period, the monthly and yearly plans of a pricing page, an app’s List and Grid views, the filters of a short list.

On phones

The card takes the full width minus the margin, the segments drop to 30 pixels and the chart is sized on the height, so everything fits the box. The pill is recomputed on resize even mid-slide. Touch picks like a click; the hover ghost pill only appears with a mouse.

With reduced motion

The pill fades out and back in on the new segment, the number and the bars change with a fade, the labels swap without moving.

Pitfalls

  • Animating the pill’s left gives a stiff slide: the stretch only comes from animating the two edges with a delay between them.
  • The label weight changes the letter width: with an equal-column grid the segments do not move and the pill needs no recalculation.
  • The digit columns must be measured in pixels and reset on resize, because the number’s size depends on the window height.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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