Skip to content
animorio
IT
All components

Text size slider

Sliders, Hover, TransitionsGSAP, CSS onlyMediumCompressed weight: Demo 6.0 KBGSAP 28 KBFreeDownload the zip

The reading settings of Leaflet, a made-up reading app: the text size slider between a small «A» and a large «A», six notches from 13 to 26 points, the knob that swells when you grab it and springs onto the nearest notch, the dark bubble with the points that follows it and rolls, and below it a preview paragraph that changes size and really rewraps, line by line. «Default» goes back to 17. On white, with a single ink-blue accent.

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>
<!--
  "Text size slider" 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>Text size slider</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/newsreader@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- the reading settings of Leaflet, a made-up reading app: a text size slider with six notches, a bubble that
         follows the knob with the size in points, and a preview paragraph that really reflows at the new size -->
    <section class="card" data-card aria-label="Leaflet reading settings">
      <header class="head">
        <div>
          <p class="brand">Leaflet · Reading</p>
          <h1 class="title">Text size</h1>
        </div>
        <button class="reset" type="button" data-reset aria-label="Back to the default size">
          <span class="reset__bg" data-reset-bg aria-hidden="true"></span>
          <span class="reset__txt">Default</span>
        </button>
      </header>

      <div class="slider" data-slider>
        <span class="glyph glyph--s" aria-hidden="true">A</span>
        <div class="rail" data-rail role="slider" tabindex="0" aria-label="Text size" aria-valuemin="13" aria-valuemax="26" aria-valuenow="17" aria-valuetext="17 points">
          <span class="track" aria-hidden="true"></span>
          <span class="fill" data-fill aria-hidden="true"></span>
          <span class="ticks" data-ticks aria-hidden="true"></span>
          <span class="knob-pos" data-knobpos aria-hidden="true">
            <span class="bubble-pos">
              <span class="bubble" data-bubble><span class="roll" data-val></span><span class="unit">pt</span></span>
            </span>
            <span class="knob" data-knob><span class="knob__dot"></span></span>
          </span>
        </div>
        <span class="glyph glyph--l" aria-hidden="true">A</span>
      </div>

      <div class="preview" aria-label="Preview">
        <p class="preview__txt" data-preview>The ferry left at seven, and by the time the island had shrunk to a pencil line on the water, Mara had read the first letter twice. It was short, and it smelled faintly of salt.</p>
      </div>

      <p class="sr" aria-live="polite" data-live></p>
    </section>
  </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

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

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 “Text size slider” 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

You grab the knob, or tap a point of the rail: the knob swells and follows your finger, the blue stretch grows behind it and the notches it passes turn pale. The bubble above the knob gives the size in points: when you pass a notch the digits roll, the bubble nods towards the direction of travel and the notch reached gives a little kick. Meanwhile the preview paragraph changes size at once and really rewraps, its lines rearranging. On release the knob snaps onto the nearest notch with a spring and shrinks back. The arrow keys, Home and End move the knob too. «Default», pale when you are already at 17, squashes and takes the knob back to 17. If nobody touches it, the demo tries the sizes by itself and goes back to Default.

How it works

The knob as a number

The state is a single number, from 0 to the number of notches minus one, halfway between two notches too: dragging writes it directly, the release spring takes it to the nearest integer with GSAP, and one function draws knob, blue stretch and notches from that number.

The text really rewraps

The paragraph’s size is a CSS variable, --pt, that GSAP slides to the new value: it is the real font-size that changes, not a scale, so the browser redoes the line breaks on every frame. The preview window has a fixed height and a fade at the bottom, so the card does not grow.

The centred bubble

The bubble sits in a zero-width positioner, centred with flex on the knob’s point; GSAP only moves the bubble inside it (the nod, the lift when grabbed), so its centre always stays on the knob’s centre.

Values to change

NameFileDefaultWhat it changes
MIN_PTscript.js13The smallest text size, in points.
MAX_PTscript.js26The largest text size, in points.
STEPSscript.js6How many notches the slider has.
DEFAULT_PTscript.js17The size the Default button goes back to.
SPRINGscript.js0.5How springy the snap onto a notch is (lower = more bounce).
GRAB_SCALEscript.js1.18How much the knob swells while you hold it.
TEXT_TIMEscript.js0.45Seconds the preview takes to reach the new size.
IDLEscript.js6Seconds after your last touch before the demo plays by itself again.

Try them in the Playground

When to use it

In the settings of a reading app, an ebook, a newspaper or a long-form blog, and in accessibility panels: readers see straight away how the text will look, before closing the settings.

On phones

Everything is in em and the size depends on both the width and the height of the window, so the card fits whole in the phone box. The rail is as tall as a fingertip and can be tapped anywhere; dragging uses pointer events, so it works with a finger as with a mouse.

With reduced motion

No springs, swelling or rolling: the knob goes straight to the notch, the digits and the preview text change at once and the demo does not play by itself.

Pitfalls

  • The bubble must not be centred with translateX(-50%) on the same element GSAP moves: GSAP’s transform would wipe the CSS one. Here a zero-width positioner centres it with flex and GSAP only moves the element inside.
  • The knob is measured in pixels from the rail’s real width, measured again on resize and when the fonts arrive: GSAP would not reread a percentage.
  • An animated font-size redoes the line breaks every frame: fine for one paragraph, not for a whole page. The preview has a fixed height so the card does not jump.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, Newsreader (font variabile) 5.3.0.

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

Testing

Tested on 2 December 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