Skip to content
animorio
IT
Back to the library

Word-by-word captions

TextGSAP, CSS onlyMediumCompressed weight: Demo 7.9 KBGSAP 28 KBFreeDownload the zip

The video of a made-up podcast, Quiet Hours, in the clean style of today’s apps: under the frame the large captions sit on two lines, and the spoken word lights up, heavier and wider through the axes of the variable typeface, while the others wait in grey. The key words take the orange, a finished line rolls up on a spring, the wave in the player bar follows the voice and the pause button stops everything.

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>
<!--
  "Word-by-word captions" 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>Video captions that light up word by word</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 video of a made-up podcast, Quiet Hours: under the frame the captions light up word by word, the spoken word
         grows in weight and width, and when a line is done the captions roll up on a spring -->
    <section class="player" data-player aria-label="Quiet Hours, video podcast with captions">
      <div class="frame" data-frame-video>
        <div class="blob blob--a" data-blob></div>
        <div class="blob blob--b" data-blob></div>
        <div class="grain" aria-hidden="true"></div>

        <p class="show"><svg class="mic" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5.5 11.5a6.5 6.5 0 0 0 13 0M12 18v3"/></svg><span data-show>Quiet Hours</span></p>
        <p class="cc" aria-hidden="true">CC</p>

        <div class="bar">
          <button class="play" type="button" data-play aria-label="Pause" aria-pressed="false">
            <span class="play__bg" data-play-bg aria-hidden="true"></span>
            <svg class="ico ico--pause" data-ico-pause viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="5.5" width="3.4" height="13" rx="1.2"/><rect x="13.6" y="5.5" width="3.4" height="13" rx="1.2"/></svg>
            <svg class="ico ico--play" data-ico-play viewBox="0 0 24 24" aria-hidden="true"><path d="M8.5 5.8v12.4a1 1 0 0 0 1.5.86l10-6.2a1 1 0 0 0 0-1.72l-10-6.2a1 1 0 0 0-1.5.86Z"/></svg>
          </button>
          <div class="wave" data-wave aria-hidden="true"></div>
          <p class="time"><span data-now>12:04</span><span class="time__all"> / <span data-all>48:10</span></span></p>
        </div>
        <div class="track" aria-hidden="true"><span class="track__fill" data-fill></span><span class="track__head" data-head></span></div>
      </div>

      <div class="captions" data-captions aria-live="off">
        <p class="who" data-who><span class="who__name" data-who-name>Ilse Brandt</span><span class="who__state" data-who-state>Paused</span></p>
        <div class="window" data-window>
          <div class="lines" data-lines></div>
        </div>
      </div>
    </section>

    <svg class="cursor" data-cursor viewBox="0 0 24 24" aria-hidden="true"><path d="M5 2.8v16.4l4.2-4 2.8 6.2 2.9-1.3-2.8-6.1h5.9Z"/></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 “Word-by-word captions” 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 near black background there is a sixteen by nine video frame with round corners: inside, two blurred patches of light, one orange and one violet, drift slowly under a light grain, at the top left the microphone with the name of the made-up podcast Quiet Hours and on the right the small CC label. At the bottom of the frame sits the player bar: the round white pause button, a wave of thin bars that rise with every spoken word and calm down between sentences, and the time, 12:04 of 48:10, moving on; below, along the edge, a thin orange line marks how far it has got. Under the video, in grey capitals, the name of the speaker, and then the large captions on two lines: all the words wait in dark grey, the spoken one lights up in white as it grows heavier and wider, with a one pixel hop, and then stays light; the key words, shout, quiet, patient and motion, light up in orange with a little extra kick. When the first line is done the two lines roll up on a spring, the old one fades and the new one arrives from below; at every change of voice the name above slides away and the other arrives. A drawn pointer presses pause: the icon turns into the play triangle, the words stop and dim, Paused appears next to the name, the wave dies down, the lights in the video slow to a halt and the dot of the current point appears on the time line. Pressed again, everything starts again; after the last sentence the captions fade and the video begins again.

How it works

The words and their timing

The speech is a list of sentences with their speakers; each word gets its moment, worked out by adding a fixed time and a time per letter, plus a pause after commas and a longer one after full stops. A paused GSAP timeline has one call per word at its moment, so pausing the video simply means stopping the timeline.

Lines measured on the widest word

The words are split into lines in JavaScript: each one is measured in its widest state, with the weight and width of the spoken word, and a line closes when the next word would not fit or when the speaker changes. So when a word grows wider it never pushes the others onto a new line; on resize the lines are rebuilt and every word goes back to its state.

Weight and width with CSS variables

Each word has font-variation-settings with two CSS variables, --g for the weight and --d for the width; GSAP animates them directly together with the colour, with back.out, so the weight goes just past and comes back. A fromTo on y gives the one pixel hop, and the key words also get a brief scale.

The line rolling up

The lines sit in a window two lines tall with hidden overflow and a mask fading the bottom; when the spoken word is on a new line the block rises by one line height with back.out, the outgoing line fades and the incoming one goes from half to full.

The wave, the time and the pause

A single gsap.ticker writes the time from the timeline’s position, stretches the time line with scaleX and raises the bars with a wave of sines multiplied by the voice, which is one at every word and calms down by itself. Pause stops the timeline, takes the timeScale of the video lights to zero and swaps the icons on a spring.

Values to change

NameFileDefaultWhat it changes
SHOWscript.js"Quiet Hours"The name of the made-up podcast, written at the top of the video.
PACEscript.js0.034The seconds per letter of each spoken word.
BASEscript.js0.14The seconds every word lasts anyway, even the shortest.
PEAKscript.js680The weight of the spoken word, on the wght axis.
STRETCHscript.js112The width of the spoken word, on the wdth axis.
ROLLscript.js0.62The seconds of the line rolling up when the previous one is done.
HOLDscript.js1.6The seconds the last sentence stays before the video starts again.

Try them in the Playground

When to use it

For a podcast or an interview on video, for vertical clips to post on social media, for the page of an app that transcribes or translates speech: captions that follow the voice word by word can be read with the sound off.

On phones

The same animation with adapted sizes: the video takes the full width, the captions are sized on the width and the height of the screen and the lines are split again, shorter; pause is pressed with a finger.

With reduced motion

No hops and no rolling lines: the words only change colour with a fade, without changing weight, the change of line is a fade, the video lights and the wave stay still and the drawn pointer is not there.

Pitfalls

  • Measuring the lines with the words in their normal state, the wider spoken word pushed the last one on the line onto a new line mid sentence: the lines are measured with every word in its widest state.
  • The time in the bar is read from the timeline, not from a separate clock: so pause also stops the time, and on resume it carries on from the same second.
  • Mona Sans’s tabular figures draw a slashed zero: the time uses the normal figures.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 7.9 KB; the libraries: GSAP 28 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 animations