# Scroll Gauge

> A figure pinned in a corner of a long page. Each section carries its value, and as you read, the figure rolls to it digit by digit, with its unit, a note and a scale of the whole story.

Scroll · scroll, counter, odometer, sticky, storytelling, long read, temperature, museum · HTML, CSS, vanilla JS · no dependencies · updated 2026-11-04
Demo: https://kodza.dev/components/scroll-gauge/
Source on GitHub: https://github.com/kodza-dev/kodza/tree/main/components/scroll-gauge

Takes the whole screen (or reacts to the page scroll): give it a page, not a small box.

## Files

The code below, served as files: byte for byte what the Kodza site copies (the CSS includes its theme guard).

- [`kodza-scroll-gauge.css`](https://kodza.dev/registry/scroll-gauge/kodza-scroll-gauge.css) · 16.2 KB
- [`kodza-scroll-gauge.js`](https://kodza.dev/registry/scroll-gauge/kodza-scroll-gauge.js) · 20.2 KB
- [`kodza-scroll-gauge.html`](https://kodza.dev/registry/scroll-gauge/kodza-scroll-gauge.html) · 1.9 KB · the markup, to adapt and paste into your page

**Can you run shell commands? Download the CSS and the JS, don't retype them.** Retyping costs thousands of tokens and can drop or change lines of the CSS. Put the files where your stack expects them (Use it says where: change the `-o` paths):

```bash
curl -fsSL --create-dirs -o kodza/kodza-scroll-gauge.css https://kodza.dev/registry/scroll-gauge/kodza-scroll-gauge.css
curl -fsSL --create-dirs -o kodza/kodza-scroll-gauge.js https://kodza.dev/registry/scroll-gauge/kodza-scroll-gauge.js
```

Then load the files from your page as Use it shows, instead of pasting the content. The HTML is the part you adapt (text, links, modifiers): paste it from the Code section. Copy the CSS and the JS from the Code section only if you can't run commands, exactly as they are. (Windows PowerShell: `curl.exe`.)

## API

- Root: `[data-kodza-scroll-gauge]`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-scroll-gauge-fg: #0a0a0a`
  - `--kz-scroll-gauge-muted: rgba(10, 10, 10, 0.62)`
  - `--kz-scroll-gauge-line: rgba(10, 10, 10, 0.1)` — the dial's edge and the rules between sections
  - `--kz-scroll-gauge-rule: rgba(10, 10, 10, 0.24)` — the scale and its ticks
  - `--kz-scroll-gauge-glass: rgba(255, 255, 255, 0.78)`
  - `--kz-scroll-gauge-shadow: 0 1px 2px rgba(10, 10, 10, 0.04), 0 14px 32px -14px rgba(10, 10, 10, 0.22)`
  - `--kz-scroll-gauge-size: 48px` — the figure
  - `--kz-scroll-gauge-width: 208px` — the narrowest the dial gets; a longer figure widens it
  - `--kz-scroll-gauge-inset: 24px` — from the bottom of the screen
  - `--kz-scroll-gauge-side: 0px` — from the side of the story (left, or right with data-side="right")
  - `--kz-scroll-gauge-radius: calc(14px * var(--kz-radius-scale, 1))`
  - `--kz-scroll-gauge-z: 20`
  - `--kz-scroll-gauge-section: 560px` — the least height of a section
  - `--kz-scroll-gauge-in: 0.6s` — the dial coming in; the figure rolls in the script's time
  - `--kz-scroll-gauge-out: 0.4s` — and going away
  - `--kz-scroll-gauge-ease: cubic-bezier(0.22, 1, 0.36, 1)`
  - `--kz-scroll-gauge-ease-out: cubic-bezier(0.65, 0, 0.35, 1)`
- Attributes:
  - `data-gauge` (e.g. `4`, `26`, `290`, `96`, `36.5`)
  - `data-gauge-note` (e.g. `Cold room`, `Shaping bench`, `Oven floor`, `Inside the crumb`, `Your hand`)
  - `data-grouping`
  - `data-kodza-scroll-gauge`
  - `data-label` (e.g. `Temperature`)
  - `data-side` (e.g. `right`)
  - `data-unit` (e.g. `°C`)
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Dark mode

The values Kodza uses on a dark background (`#0a0a0a`). For a page that follows the system theme, add them after the component's CSS:

```css
@media (prefers-color-scheme: dark) {
  .kodza-scroll-gauge {
    --kz-scroll-gauge-fg: #f2f2f0;
    --kz-scroll-gauge-muted: rgba(242, 242, 240, 0.62);
    --kz-scroll-gauge-line: rgba(255, 255, 255, 0.14);
    --kz-scroll-gauge-rule: rgba(255, 255, 255, 0.3);
    --kz-scroll-gauge-glass: rgba(22, 22, 22, 0.72);
    --kz-scroll-gauge-shadow: 0 14px 32px -14px rgba(0, 0, 0, 0.6);
  }
}
```

A site with its own theme switch puts the same rules under its dark selector instead (`[data-theme="dark"] .kodza-scroll-gauge { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-scroll-gauge.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-scroll-gauge.css">`. Without a shell, paste it in a `<style>` in `<head>` instead. It only touches `kodza-` classes.
- HTML: where the component goes. Paste it as many times as you need: instances never interfere.
- JS: `kodza/kodza-scroll-gauge.js`, loaded with `<script src="kodza/kodza-scroll-gauge.js" defer></script>` in `<head>`. Without a shell, paste it in a `<script>` before `</body>` (or in `<head>`: it waits for the page). One copy per page, whatever the number of instances.
- Restyle with the `--kz-…` variables, set on the component's root element itself (the root declares its own defaults, so a value on an ancestor is ignored), and with the modifiers / attributes listed under API.
- Font: it takes the page's own. A site with its own type sets it once for every Kodza component, on `:root`, never by editing the CSS (unset, nothing changes): `--kz-font-display`, the display face (headings, big numbers, wordmarks); `--kz-font-display-weight`, its weight; `--kz-font-display-scale`, a multiplier on its sizes (1 by default); `--kz-font-display-tracking`, its letter-spacing; `--kz-font-display-case`, its case (`uppercase`…); `--kz-font-label`, the face of the small labels (meta, captions, counters, hints, footer links, button labels); `--kz-font-label-size`, their size, one for all of them (`11px`…); `--kz-font-label-weight`, their weight; `--kz-font-label-tracking`, their letter-spacing; `--kz-font-label-case`, their case (`uppercase`…; code and units keep theirs); `--kz-font-label-leading`, their line-height (`1.45`…; buttons, pills and keys keep their box); `--kz-font-mono`, the monospace face (code, labels, counters). The Kodza look is Geist: `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Corners: a site with its own shapes sets them once for every Kodza component, on `:root`, never by editing the CSS (unset, nothing changes): `--kz-radius-scale` multiplies every corner (`0` square, `0.5` softer, `1` Kodza).
- Motion: a site sets its pace once for every Kodza component, on `:root`, never by editing the CSS or the JS: `--kz-motion-scale` multiplies every duration (`0.5` twice as fast, `2` twice as slow, `0` no motion at all, loops stopped, like reduced motion). Unset, nothing changes.
- Content added later (AJAX navigation, a SPA route, a builder preview): start it with `document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: container } }))`; before removing it, the same call with `'kodza:destroy'` stops it and puts the original markup back.

### Claude artifact (claude.ai)

- Paste the CSS in a `<style>` and the JS in a `<script>` at the end, in the artifact itself: it loads stylesheets only from Google Fonts and scripts only from a few CDNs, so no `<link>` or `<script src>` to Kodza.
- Writing the artifact file with a shell? Insert the downloaded files (Files) with a command instead of retyping them: a line `KODZA-CSS` alone inside the `<style>`, `KODZA-JS` inside the `<script>`, then `sed -e '/^KODZA-CSS$/{r kodza/kodza-scroll-gauge.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-scroll-gauge.js' -e 'd' -e '}' page.html > artifact.html`.
- Font: load Geist from Google Fonts (allowed): `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`. A site with its own type sets it once for every Kodza component, on `:root`, never by editing the CSS (unset, nothing changes): `--kz-font-display`, the display face (headings, big numbers, wordmarks); `--kz-font-display-weight`, its weight; `--kz-font-display-scale`, a multiplier on its sizes (1 by default); `--kz-font-display-tracking`, its letter-spacing; `--kz-font-display-case`, its case (`uppercase`…); `--kz-font-label`, the face of the small labels (meta, captions, counters, hints, footer links, button labels); `--kz-font-label-size`, their size, one for all of them (`11px`…); `--kz-font-label-weight`, their weight; `--kz-font-label-tracking`, their letter-spacing; `--kz-font-label-case`, their case (`uppercase`…; code and units keep theirs); `--kz-font-label-leading`, their line-height (`1.45`…; buttons, pills and keys keep their box); `--kz-font-mono`, the monospace face (code, labels, counters).
- Corners: a site with its own shapes sets them once for every Kodza component, on `:root`, never by editing the CSS (unset, nothing changes): `--kz-radius-scale` multiplies every corner (`0` square, `0.5` softer, `1` Kodza).
- Motion: a site sets its pace once for every Kodza component, on `:root`, never by editing the CSS or the JS: `--kz-motion-scale` multiplies every duration (`0.5` twice as fast, `2` twice as slow, `0` no motion at all, loops stopped, like reduced motion). Unset, nothing changes.
- Dark mode: the viewer sets `data-theme="dark"` or `"light"` on `<html>`, or nothing when it follows the system. Write the Dark mode rules twice: inside `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])` in front of each selector, and with `:root[data-theme="dark"]` in front of each selector.

### WordPress

- HTML: a **Custom HTML** block (or a pattern / template part). WordPress keeps this markup as it is only for users allowed to post unfiltered HTML (Administrators; Super Admins on multisite): for anyone else it strips tags such as `<svg>`, `<input>` or `<dialog>`, so add it from the theme (a pattern or template part) instead.
- This one spans the page: a block theme keeps a Custom HTML block to the width of the text column, so put it inside a **Group** block set to **Full width**, with **Inner blocks use content width** turned off.
- CSS and JS: the downloaded files go in the theme, under `wp-content/themes/<your-theme>/kodza/` (the child theme if there is one), enqueued from its functions.php (or a code-snippets plugin):
  ```php
  add_action('wp_enqueue_scripts', function () {
    $dir = get_stylesheet_directory() . '/kodza/';
    $uri = get_stylesheet_directory_uri() . '/kodza/';
    wp_enqueue_style('kodza-scroll-gauge', $uri . 'kodza-scroll-gauge.css', [], filemtime($dir . 'kodza-scroll-gauge.css'));
    wp_enqueue_script('kodza-scroll-gauge', $uri . 'kodza-scroll-gauge.js', [], filemtime($dir . 'kodza-scroll-gauge.js'), true);
  });
  ```
  Scoped to `kodza-` classes, the CSS never touches the theme. One copy of the JS, whatever the number of blocks.
- No access to the theme files? The CSS can also go, as it is, in **Appearance → Customize → Additional CSS** (classic theme) or **Styles → Additional CSS** in the Site Editor (block theme).
- Theme with AJAX page transitions: fire `kodza:init` on the new content after each swap (and `kodza:destroy` on the old one).
- Performance plugin (WP Rocket, LiteSpeed Cache, Perfmatters…) with **Delay JavaScript execution** turned on: add `kodza` to the scripts it must not delay. Otherwise the component waits for the visitor's first scroll, tap or mouse move, and that first click can be lost.
- Colours: it takes the colour of the text around it (or keeps its own monochrome): nothing to point at the theme.
- WordPress turns straight quotes and `--` into typographic ones in the text of a Custom HTML block (not inside `<code>` or `<pre>`).

#### With Elementor

- HTML: an **HTML** widget (Elementor shows it to administrators only). It keeps the code exactly as pasted, straight quotes included.
- This one spans the page: give the widget its own container, **Content Width: Full Width**, padding 0.
- CSS and JS: as above. Elementor's Site Settings → Theme Style styles every button, field, link and image of the page, components included; the theme guard at the end of the CSS keeps the component's buttons, fields and link colours as they are.
- The Elementor editor redraws each widget after the page has loaded: without the script below, the component stays still in the editor preview (the published page works). Add it once per site, in the footer like the component's script (`kodza/elementor-editor.js`, or a code-snippets plugin):

```js
// Kodza in the Elementor editor: the editor redraws each HTML widget after the page has loaded.
// Start Kodza in what it draws, stop it in what it replaces or removes. Once per site.
window.addEventListener('elementor/frontend/init', () => {
  if (!elementorFrontend.isEditMode()) return;
  class KodzaWidget extends elementorModules.frontend.handlers.Base {
    onInit() {
      super.onInit();
      this.kodza = [...this.$element[0].children];
      document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: this.$element[0] } }));
    }
    onDestroy() {
      super.onDestroy();
      this.kodza.forEach((root) => document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } })));
    }
  }
  elementorFrontend.elementsHandler.attachHandler('html', KodzaWidget);
});
```

- No child theme: everything can go in the HTML widget instead, `<style>` with the CSS, the HTML, then `<script>` with the JS. It works on the page and in the editor without the script above.

### Shopify

- Files: `assets/kodza-scroll-gauge.css` and `assets/kodza-scroll-gauge.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-scroll-gauge.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-scroll-gauge.js' | asset_url }}" defer></script>`, then the HTML.
- The theme editor re-renders sections: restart them with
  `document.addEventListener('shopify:section:load', (e) => document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: e.target } })));`
  and the same with `shopify:section:unload` → `kodza:destroy`.

### React / Next.js

- Files, side by side (e.g. in `components/kodza/`): `ScrollGauge.tsx` (below), the CSS block under Code saved as `scroll-gauge.css` and the JS block as `scroll-gauge.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { ScrollGauge } from '@/components/kodza/ScrollGauge';` then `<ScrollGauge />`. Props: `label` (`data-label`: "Temperature"), `unit` (`data-unit`: "°C"), `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-scroll-gauge-fg': … }}`), `className`, `style` and the other props of its `<div>` (`onClick`, `aria-…`).
- Next.js App Router: it is a Client Component already (`'use client'`). Pages Router: Next.js takes global CSS only in `pages/_app`, so move the `import './scroll-gauge.css'` line there.
- Safe under StrictMode, client-side navigation and prop changes: when a prop changes, the `key` gives React a fresh element, `kodza:destroy` stops the script on the old one and `kodza:init` starts it on the new one.
- Built from your data (tabs, rows, options)? Add what the markup is made of to the `key`, as plain values (ids, text, numbers). What the visitor changes (the open tab, the sort, what they type) is the script's: follow it with `onClick` or `onInput` on the root, and change it from your code as a visitor would (click the tab; set the field's value, then dispatch a bubbling `input` event). Fields stay uncontrolled (`defaultValue`, `name`).

```tsx
'use client';
// Kodza — Scroll Gauge, for React. From https://kodza.dev/components/scroll-gauge/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: scroll-gauge.css and scroll-gauge.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
// data-kodza-manual keeps the script from starting it on its own: the effect below does, once
// React has hydrated the markup (on a page that streams in, the script can load first).
// Built from your data (tabs, rows, options)? Put what the markup is made of in the key, as plain
// values (ids, text, numbers): a change starts the script again on fresh markup. What the visitor
// changes (the open tab, the sort, what they type) is the script's: keep it out of the key, follow
// it with onClick or onInput on the root, and change it from your code as a visitor would (click
// the tab; set the field's value, then dispatch a bubbling input event).
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './scroll-gauge.css';

export type ScrollGaugeProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars" | "label" | "unit"> & {
  /** data-label on the root (default: Temperature) */
  label?: "Temperature";
  /** data-unit on the root (default: °C) */
  unit?: "°C";
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #0a0a0a */
    "--kz-scroll-gauge-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.62) */
    "--kz-scroll-gauge-muted"?: string | number;
    /** the dial's edge and the rules between sections — default: rgba(10, 10, 10, 0.1) */
    "--kz-scroll-gauge-line"?: string | number;
    /** the scale and its ticks — default: rgba(10, 10, 10, 0.24) */
    "--kz-scroll-gauge-rule"?: string | number;
    /** default: rgba(255, 255, 255, 0.78) */
    "--kz-scroll-gauge-glass"?: string | number;
    /** default: 0 1px 2px rgba(10, 10, 10, 0.04), 0 14px 32px -14px rgba(10, 10, 10, 0.22) */
    "--kz-scroll-gauge-shadow"?: string | number;
    /** the figure — default: 48px */
    "--kz-scroll-gauge-size"?: string | number;
    /** the narrowest the dial gets; a longer figure widens it — default: 208px */
    "--kz-scroll-gauge-width"?: string | number;
    /** from the bottom of the screen — default: 24px */
    "--kz-scroll-gauge-inset"?: string | number;
    /** from the side of the story (left, or right with data-side="right") — default: 0px */
    "--kz-scroll-gauge-side"?: string | number;
    /** default: calc(14px * var(--kz-radius-scale, 1)) */
    "--kz-scroll-gauge-radius"?: string | number;
    /** default: 20 */
    "--kz-scroll-gauge-z"?: string | number;
    /** the least height of a section — default: 560px */
    "--kz-scroll-gauge-section"?: string | number;
    /** the dial coming in; the figure rolls in the script's time — default: 0.6s */
    "--kz-scroll-gauge-in"?: string | number;
    /** and going away — default: 0.4s */
    "--kz-scroll-gauge-out"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-scroll-gauge-ease"?: string | number;
    /** default: cubic-bezier(0.65, 0, 0.35, 1) */
    "--kz-scroll-gauge-ease-out"?: string | number;
  };
  className?: string;
};

export function ScrollGauge({ label = "Temperature", unit = "°C", vars, className, style, ...rest }: ScrollGaugeProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-scroll-gauge", className].filter(Boolean).join(' ');
  // Everything the markup is made of: when it changes, React gets a fresh element (see the top)
  const key = JSON.stringify([classes, label, unit, vars, style, rest]);

  // Starts the script on this element once React has rendered it, stops it when it goes
  useEffect(() => {
    const root = ref.current;
    let live = true;
    // @ts-ignore: a plain script, no types to find
    import('./scroll-gauge.js').then(() => {
      if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
    });
    return () => {
      live = false;
      document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
    };
  }, [key]);

  return (
    <div data-kodza-scroll-gauge="" key={key} {...rest} className={classes} data-kodza-manual data-label={label} data-unit={unit} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <section className="kodza-scroll-gauge__section" data-gauge="4" data-gauge-note="Cold room">
        <p className="kodza-scroll-gauge__time">21:00</p>
        <h2 className="kodza-scroll-gauge__title">The dough sleeps.</h2>
        <p className="kodza-scroll-gauge__text">Twelve hours at four degrees and nobody touches it. Flavour is just time you did not rush.</p>
      </section>
      <section className="kodza-scroll-gauge__section" data-gauge="26" data-gauge-note="Shaping bench">
        <p className="kodza-scroll-gauge__time">04:00</p>
        <h2 className="kodza-scroll-gauge__title">Hands, flour, no playlist.</h2>
        <p className="kodza-scroll-gauge__text">The bench is warm and the dough wakes up. Shape it before it makes plans of its own.</p>
      </section>
      <section className="kodza-scroll-gauge__section" data-gauge="290" data-gauge-note="Oven floor">
        <p className="kodza-scroll-gauge__time">05:10</p>
        <h2 className="kodza-scroll-gauge__title">Stone, steam, no mercy.</h2>
        <p className="kodza-scroll-gauge__text">A wood-fired oven, lit at midnight. Twenty-five minutes, one cloud of steam, and a crust that crackles as it cools.</p>
      </section>
      <section className="kodza-scroll-gauge__section" data-gauge="96" data-gauge-note="Inside the crumb">
        <p className="kodza-scroll-gauge__time">05:35</p>
        <h2 className="kodza-scroll-gauge__title">Done is a number.</h2>
        <p className="kodza-scroll-gauge__text">Not “golden brown”, not hollow when you knock. A probe in the middle says 96 and the debate is over.</p>
      </section>
      <section className="kodza-scroll-gauge__section" data-gauge="36.5" data-gauge-note="Your hand">
        <p className="kodza-scroll-gauge__time">07:00</p>
        <h2 className="kodza-scroll-gauge__title">Still warm. Yours now.</h2>
        <p className="kodza-scroll-gauge__text">The shop opens at seven. Ninety minutes out of the oven, the loaf is the temperature of the hand holding it.</p>
      </section>
    </div>
  );
}
```

## Code

```html
<div class="kodza-scroll-gauge" data-kodza-scroll-gauge data-label="Temperature" data-unit="°C">
  <section class="kodza-scroll-gauge__section" data-gauge="4" data-gauge-note="Cold room">
    <p class="kodza-scroll-gauge__time">21:00</p>
    <h2 class="kodza-scroll-gauge__title">The dough sleeps.</h2>
    <p class="kodza-scroll-gauge__text">Twelve hours at four degrees and nobody touches it. Flavour is just time you did not rush.</p>
  </section>
  <section class="kodza-scroll-gauge__section" data-gauge="26" data-gauge-note="Shaping bench">
    <p class="kodza-scroll-gauge__time">04:00</p>
    <h2 class="kodza-scroll-gauge__title">Hands, flour, no playlist.</h2>
    <p class="kodza-scroll-gauge__text">The bench is warm and the dough wakes up. Shape it before it makes plans of its own.</p>
  </section>
  <section class="kodza-scroll-gauge__section" data-gauge="290" data-gauge-note="Oven floor">
    <p class="kodza-scroll-gauge__time">05:10</p>
    <h2 class="kodza-scroll-gauge__title">Stone, steam, no mercy.</h2>
    <p class="kodza-scroll-gauge__text">A wood-fired oven, lit at midnight. Twenty-five minutes, one cloud of steam, and a crust that crackles as it cools.</p>
  </section>
  <section class="kodza-scroll-gauge__section" data-gauge="96" data-gauge-note="Inside the crumb">
    <p class="kodza-scroll-gauge__time">05:35</p>
    <h2 class="kodza-scroll-gauge__title">Done is a number.</h2>
    <p class="kodza-scroll-gauge__text">Not “golden brown”, not hollow when you knock. A probe in the middle says 96 and the debate is over.</p>
  </section>
  <section class="kodza-scroll-gauge__section" data-gauge="36.5" data-gauge-note="Your hand">
    <p class="kodza-scroll-gauge__time">07:00</p>
    <h2 class="kodza-scroll-gauge__title">Still warm. Yours now.</h2>
    <p class="kodza-scroll-gauge__text">The shop opens at seven. Ninety minutes out of the oven, the loaf is the temperature of the hand holding it.</p>
  </section>
</div>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Scroll Gauge
   A real figure pinned in a corner of a long page. Each section carries its value; once you
   read it, the figure rolls there digit by digit like an odometer (up when it climbs, down when
   it falls), its note rolls with it and a needle slides along the scale of the whole story.
   The dial rides along at the bottom of the screen and leaves with the end of the story.
   Everything is tuned with the --kz-scroll-gauge-* variables. */
.kodza-scroll-gauge {
  --kz-scroll-gauge-fg: #0a0a0a;
  --kz-scroll-gauge-muted: rgba(10, 10, 10, 0.62);
  --kz-scroll-gauge-line: rgba(10, 10, 10, 0.1); /* the dial's edge and the rules between sections */
  --kz-scroll-gauge-rule: rgba(10, 10, 10, 0.24); /* the scale and its ticks */
  --kz-scroll-gauge-glass: rgba(255, 255, 255, 0.78);
  --kz-scroll-gauge-shadow: 0 1px 2px rgba(10, 10, 10, 0.04), 0 14px 32px -14px rgba(10, 10, 10, 0.22);
  --kz-scroll-gauge-size: 48px; /* the figure */
  --kz-scroll-gauge-width: 208px; /* the narrowest the dial gets; a longer figure widens it */
  --kz-scroll-gauge-inset: 24px; /* from the bottom of the screen */
  --kz-scroll-gauge-side: 0px; /* from the side of the story (left, or right with data-side="right") */
  --kz-scroll-gauge-radius: calc(14px * var(--kz-radius-scale, 1));
  --kz-scroll-gauge-z: 20;
  --kz-scroll-gauge-section: 560px; /* the least height of a section */
  --kz-scroll-gauge-in: 0.6s; /* the dial coming in; the figure rolls in the script's time */
  --kz-scroll-gauge-out: 0.4s; /* and going away */
  --kz-scroll-gauge-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --kz-scroll-gauge-ease-out: cubic-bezier(0.65, 0, 0.35, 1);

  color: var(--kz-scroll-gauge-fg);
}

/* The story: a rule, the time on the left, the words on the right */
.kodza-scroll-gauge__section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  gap: 16px 64px;
  align-content: start;
  box-sizing: border-box;
  min-height: var(--kz-scroll-gauge-section);
  padding: 28px 0 64px;
  border-top: 1px solid var(--kz-scroll-gauge-line);
}

.kodza-scroll-gauge__time {
  margin: 0;
  padding-top: 0.5em;
  font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
  font-size: var(--kz-font-label-size, 12px);
  font-weight: var(--kz-font-label-weight, 400);
  line-height: var(--kz-font-label-leading, 1.4);
  letter-spacing: var(--kz-font-label-tracking, normal);
  text-transform: var(--kz-font-label-case, none);
  color: var(--kz-scroll-gauge-muted);
}

.kodza-scroll-gauge__title {
  margin: 0;
  font-family: var(--kz-font-display, inherit);
  font-size: calc(clamp(30px, 4vw, 52px) * var(--kz-font-display-scale, 1));
  font-weight: var(--kz-font-display-weight, 600);
  line-height: 1.02;
  letter-spacing: var(--kz-font-display-tracking, -0.045em);
  text-transform: var(--kz-font-display-case, inherit);
  text-wrap: balance;
}

.kodza-scroll-gauge__text {
  grid-column: 2;
  max-width: 30em;
  margin: 4px 0 0;
  font-size: 17px;
  line-height: 1.55;
  color: var(--kz-scroll-gauge-muted);
  text-wrap: pretty;
}

/* The dial, on a rail of no height pinned to the bottom of the screen: it rides along while the
   story scrolls, and goes up with the end of it */
.kodza-scroll-gauge__rail {
  position: sticky;
  bottom: var(--kz-scroll-gauge-inset);
  z-index: var(--kz-scroll-gauge-z);
  height: 0;
  pointer-events: none;
}

/* A shutter: it opens from its bottom edge up, and closes back down. The clip leaves room for
   the shadow */
.kodza-scroll-gauge__dial {
  position: absolute;
  bottom: 0;
  left: var(--kz-scroll-gauge-side);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  min-width: var(--kz-scroll-gauge-width);
  padding: 13px 18px 16px;
  border: 1px solid var(--kz-scroll-gauge-line);
  border-radius: var(--kz-scroll-gauge-radius);
  background: var(--kz-scroll-gauge-glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: var(--kz-scroll-gauge-shadow);
  color: var(--kz-scroll-gauge-fg);
  clip-path: inset(calc(100% + 48px) -48px -48px -48px);
  transition: clip-path calc(var(--kz-scroll-gauge-out) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease-out);
}

.kodza-scroll-gauge[data-side="right"] .kodza-scroll-gauge__dial {
  right: var(--kz-scroll-gauge-side);
  left: auto;
}

.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__dial {
  clip-path: inset(-48px);
  transition: clip-path calc(var(--kz-scroll-gauge-in) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease);
}

/* What it measures, in small type, rising from behind its line */
.kodza-scroll-gauge__label {
  display: block;
  overflow: hidden;
  overflow: clip;
  font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
  font-size: var(--kz-font-label-size, 12px);
  font-weight: var(--kz-font-label-weight, 400);
  line-height: var(--kz-font-label-leading, 1.4);
  letter-spacing: var(--kz-font-label-tracking, normal);
  text-transform: var(--kz-font-label-case, none);
  white-space: nowrap;
  color: var(--kz-scroll-gauge-muted);
}

.kodza-scroll-gauge__label .kodza-scroll-gauge__in,
.kodza-scroll-gauge__unit .kodza-scroll-gauge__in {
  display: block;
  transform: translateY(110%);
  transition: transform calc(var(--kz-scroll-gauge-out) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease-out);
}

.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__label .kodza-scroll-gauge__in,
.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__unit .kodza-scroll-gauge__in {
  transform: none;
  transition: transform calc(var(--kz-scroll-gauge-in) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease) calc(0.08s * var(--kz-motion-scale, 1));
}

.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__unit .kodza-scroll-gauge__in {
  transition-delay: calc(0.16s * var(--kz-motion-scale, 1));
}

/* The figure and its unit */
.kodza-scroll-gauge__reading {
  display: flex;
  align-items: flex-start;
  margin-top: 4px;
  font-family: var(--kz-font-display, inherit);
  font-size: calc(var(--kz-scroll-gauge-size) * var(--kz-font-display-scale, 1));
  font-weight: var(--kz-font-display-weight, 600);
  line-height: 1.1;
  letter-spacing: var(--kz-font-display-tracking, -0.045em);
  text-transform: var(--kz-font-display-case, inherit);
}

.kodza-scroll-gauge__figure {
  position: relative;
  display: flex;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}

/* One slot per character: a digit spins in its window, an unused one closes to no width */
.kodza-scroll-gauge__digit,
.kodza-scroll-gauge__char {
  position: relative;
  display: block;
  flex: none;
  width: 0.62em;
  height: 1.1em;
  overflow: hidden;
  overflow: clip;
  text-align: center;
  transition:
    width calc(0.6s * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease),
    opacity calc(0.6s * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease);
}

/* A slot closing fades with its width, so no half digit is left at its edge */
.kodza-scroll-gauge__digit.is-closed,
.kodza-scroll-gauge__char.is-closed {
  opacity: 0;
}

.kodza-scroll-gauge__strip {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
}

.kodza-scroll-gauge__cell {
  display: block;
  height: 1.1em;
}

/* Measures the widest digit in the page's own font, then leaves */
.kodza-scroll-gauge__probe {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  white-space: nowrap;
}

.kodza-scroll-gauge__unit {
  display: block;
  overflow: hidden;
  overflow: clip;
  margin: 0.22em 0 0 0.16em;
  font-size: 0.4em;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  color: var(--kz-scroll-gauge-muted);
}

/* The note of the section being read: every note in one cell, so the dial keeps its width */
.kodza-scroll-gauge__note {
  display: grid;
  overflow: hidden;
  overflow: clip;
  margin-top: 2px;
  font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
  font-size: var(--kz-font-label-size, 12px);
  font-weight: var(--kz-font-label-weight, 400);
  line-height: var(--kz-font-label-leading, 1.4);
  letter-spacing: var(--kz-font-label-tracking, normal);
  text-transform: var(--kz-font-label-case, none);
}

.kodza-scroll-gauge__line {
  grid-area: 1 / 1;
  white-space: nowrap;
  transform: translateY(110%);
}

.kodza-scroll-gauge__line.is-current {
  transform: none;
}

/* The scale of the whole story: a tick for each section, the needle on the one being read. It
   draws itself from the left as the dial comes in */
.kodza-scroll-gauge__scale {
  position: relative;
  height: 9px;
  margin-top: 12px;
  clip-path: inset(0 100% 0 0);
  transition: clip-path calc(var(--kz-scroll-gauge-out) * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease-out);
}

.kodza-scroll-gauge.is-shown .kodza-scroll-gauge__scale {
  clip-path: inset(0);
  transition: clip-path calc(0.9s * var(--kz-motion-scale, 1)) var(--kz-scroll-gauge-ease) calc(0.1s * var(--kz-motion-scale, 1));
}

.kodza-scroll-gauge__track {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 1px;
  background: var(--kz-scroll-gauge-rule);
}

.kodza-scroll-gauge__stop {
  position: absolute;
  bottom: 0;
  width: 1px;
  height: 5px;
  background: var(--kz-scroll-gauge-rule);
}

/* The needle moves across its own width (the scale less its 2 px), so 100% is the far end */
.kodza-scroll-gauge__needle {
  position: absolute;
  bottom: 0;
  left: 0;
  width: calc(100% - 2px);
  height: 100%;
}

.kodza-scroll-gauge__tick {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 2px;
  height: 100%;
  background: var(--kz-scroll-gauge-fg);
}

/* What the dial says, for screen readers */
.kodza-scroll-gauge__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 720px) {
  .kodza-scroll-gauge {
    --kz-scroll-gauge-size: 36px;
    --kz-scroll-gauge-width: 172px;
    --kz-scroll-gauge-inset: 16px;
    --kz-scroll-gauge-section: 480px;
  }

  .kodza-scroll-gauge__section {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding-bottom: 48px;
  }

  .kodza-scroll-gauge__text {
    grid-column: auto;
    font-size: 16px;
  }

  .kodza-scroll-gauge__dial {
    padding: 11px 14px 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-scroll-gauge *,
  .kodza-scroll-gauge *::before,
  .kodza-scroll-gauge *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* Dark mode: set the colours on the root, for instance
   .dark .kodza-scroll-gauge {
     --kz-scroll-gauge-fg: #f2f2f0;
     --kz-scroll-gauge-muted: rgba(242, 242, 240, 0.62);
     --kz-scroll-gauge-line: rgba(255, 255, 255, 0.14);
     --kz-scroll-gauge-rule: rgba(255, 255, 255, 0.3);
     --kz-scroll-gauge-glass: rgba(22, 22, 22, 0.72);
     --kz-scroll-gauge-shadow: 0 14px 32px -14px rgba(0, 0, 0, 0.6);
   } */

/* kodza-guard 7194bfa037ff — generated by Kodza, do not edit.
   Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
   component. :not(#_) is always true and weighs as much as an id, so these lines win over
   theme rules made of classes and tags. Customise the component through its --kz-* variables. */

/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */

:where(.kodza-scroll-gauge__time):not(#_),
:where(.kodza-scroll-gauge__title):not(#_),
:where(.kodza-scroll-gauge__text):not(#_) {
  transition-duration: revert;
}

/* What the browser gives, on everything the component leaves to it */

.kodza-scroll-gauge:not(#_),
.kodza-scroll-gauge__rail:not(#_),
.kodza-scroll-gauge__label:not(#_),
.kodza-scroll-gauge__in:not(#_),
.kodza-scroll-gauge__reading:not(#_),
.kodza-scroll-gauge__figure:not(#_),
.kodza-scroll-gauge__digit:not(#_),
.kodza-scroll-gauge__strip:not(#_),
.kodza-scroll-gauge__cell:not(#_),
.kodza-scroll-gauge__char:not(#_),
.kodza-scroll-gauge__unit:not(#_),
.kodza-scroll-gauge__note:not(#_),
.kodza-scroll-gauge__line:not(#_),
.kodza-scroll-gauge__scale:not(#_),
.kodza-scroll-gauge__track:not(#_),
.kodza-scroll-gauge__stop:not(#_),
.kodza-scroll-gauge__needle:not(#_),
.kodza-scroll-gauge__tick:not(#_),
.kodza-scroll-gauge__sr:not(#_) {
  box-sizing: revert;
}

.kodza-scroll-gauge__time:not(#_) {
  border: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  padding-right: revert;
  padding-bottom: revert;
  padding-left: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-style: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  transition-property: revert;
  transition-timing-function: revert;
  transition-delay: revert;
}

.kodza-scroll-gauge__title:not(#_) {
  border: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-style: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  transition-property: revert;
  transition-timing-function: revert;
  transition-delay: revert;
}

.kodza-scroll-gauge__text:not(#_) {
  border: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-height: revert;
  font-family: revert;
  font-weight: revert;
  font-style: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  transition-property: revert;
  transition-timing-function: revert;
  transition-delay: revert;
}

.kodza-scroll-gauge__time:not(#_):where(:not([hidden])),
.kodza-scroll-gauge__title:not(#_):where(:not([hidden])),
.kodza-scroll-gauge__text:not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-scroll-gauge__time:not(#_):where([hidden]),
.kodza-scroll-gauge__title:not(#_):where([hidden]),
.kodza-scroll-gauge__text:not(#_):where([hidden]) {
  display: none;
}

/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */

.kodza-scroll-gauge__time:not(#_) {
  margin: 0;
  padding-top: 0.5em;
  font-family: var(--kz-font-label, var(--kz-font-mono, "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace));
  font-size: var(--kz-font-label-size, 12px);
  font-weight: var(--kz-font-label-weight, 400);
  line-height: var(--kz-font-label-leading, 1.4);
  letter-spacing: var(--kz-font-label-tracking, normal);
  text-transform: var(--kz-font-label-case, none);
  color: var(--kz-scroll-gauge-muted);
}

.kodza-scroll-gauge__title:not(#_) {
  margin: 0;
  font-family: var(--kz-font-display, inherit);
  font-size: calc(clamp(30px, 4vw, 52px) * var(--kz-font-display-scale, 1));
  font-weight: var(--kz-font-display-weight, 600);
  line-height: 1.02;
  letter-spacing: var(--kz-font-display-tracking, -0.045em);
  text-transform: var(--kz-font-display-case, inherit);
}

.kodza-scroll-gauge__text:not(#_) {
  max-width: 30em;
  margin: 4px 0 0;
  font-size: 17px;
  line-height: 1.55;
  color: var(--kz-scroll-gauge-muted);
}

@media (max-width: 720px) {
  .kodza-scroll-gauge__text:not(#_) {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-scroll-gauge *:where(p, h2):not(#_) {
    transition-duration: 0.01ms !important;
  }
}
```

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Scroll Gauge
// A real figure pinned in a corner that follows the reading. Each section carries its value
// (data-gauge="290", a plain number with a dot for decimals: "36.5" keeps one) and, if you like,
// a note (data-gauge-note="Oven floor"). Once a section's top passes the reading line, the figure
// rolls to its value digit by digit, like an odometer: up when the value climbs, down when it
// falls, and the needle slides along the scale of the whole story.
// On the root: data-label (what it measures), data-unit, data-side="right" for the right corner,
// data-grouping for thousands separators (an amount has them, a year does not).
// Settings: the --kz-scroll-gauge-* variables in the CSS, and the constants below.
(() => {
  const SELECTOR = '[data-kodza-scroll-gauge]';
  const LINE = 0.6; // the reading line, from the top of the screen (0 to 1): a section is read once its top passes it
  const LINE_SHORT = 0.5; // the reading line on a screen 720 px tall or less, where a section shows less of itself
  const ROLL = 1100; // ms: the highest digit that changes rolls straight to its new value in this time
  const LAG = 150; // ms more for each digit on its right, which spin past and land later
  const TURNS = 2; // full turns of the last digit; the digits in between spin 1 to this
  const NOTE = 650; // ms: the note rolling to the next section's
  const EASE = 'cubic-bezier(0.16, 1, 0.3, 1)'; // fast start, gentle landing: an odometer settling
  const NOTE_EASE = 'cubic-bezier(0.22, 1, 0.36, 1)';
  const CELL = 1.1; // em: the height of a digit window, the line-height of the figure in the CSS

  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  // The site's pace, --kz-motion-scale (set on :root, read on the instance): every duration of the
  // script times it, and 0 moves nothing, like reduced motion
  const paceOf = (el) => {
    const pace = parseFloat(getComputedStyle(el).getPropertyValue('--kz-motion-scale'));
    return pace >= 0 ? pace : 1;
  };

  // One instance, with its own state: two copies on a page never interfere. Everything it
  // starts is tied to `signal` (listeners get { signal }, observers and timers stop on its
  // 'abort' event), so kodza:destroy stops it all.
  function mount(root, signal) {
    const pace = paceOf(root);
    const still = reduceMotion || !pace; // the still path: no motion asked, by the visitor or the site

    // The story: every section with a value, in the order of the page (inside nested blocks too)
    const stops = [...root.querySelectorAll('[data-gauge]')]
      .filter((el) => el.closest(SELECTOR) === root)
      .map((el) => {
        const raw = el.getAttribute('data-gauge').replace(/\s/g, '').replace('−', '-');
        return {
          el,
          raw,
          value: Number(raw),
          decimals: (raw.split('.')[1] || '').length,
          note: (el.getAttribute('data-gauge-note') || '').trim(),
        };
      })
      .filter((stop) => stop.raw !== '' && Number.isFinite(stop.value));
    if (!stops.length) return;

    const label = (root.getAttribute('data-label') || '').trim();
    const unit = (root.getAttribute('data-unit') || '').trim();
    const grouping = root.hasAttribute('data-grouping');
    // The decimal point and the thousands separator of the page's language (36,5 in French)
    const lang = root.closest('[lang]')?.getAttribute('lang') || undefined;
    let decimalChar = '.';
    let groupChar = ',';
    try {
      const parts = new Intl.NumberFormat(lang).formatToParts(12345.6);
      decimalChar = parts.find((part) => part.type === 'decimal')?.value || '.';
      groupChar = parts.find((part) => part.type === 'group')?.value || ',';
    } catch (error) {
      // An unknown language tag: the dot and the comma
    }
    const spoken = (stop) => {
      try {
        return new Intl.NumberFormat(lang, { minimumFractionDigits: stop.decimals, maximumFractionDigits: stop.decimals, useGrouping: grouping }).format(stop.value);
      } catch (error) {
        return stop.raw;
      }
    };

    // The places of the figure: as many whole digits and decimals as the longest value needs.
    // A value shows only its own: no leading zeros, no decimals it does not have
    const DECIMALS = Math.max(...stops.map((stop) => stop.decimals));
    const scaled = (stop) => Math.round(Math.abs(stop.value) * 10 ** DECIMALS);
    const wholeLength = (stop) => String(Math.floor(scaled(stop) / 10 ** DECIMALS)).length;
    const WHOLE = Math.max(...stops.map(wholeLength));
    const PLACES = WHOLE + DECIMALS;
    const shapeOf = (stop) => {
      const digits = String(scaled(stop)).padStart(PLACES, '0').split('').map(Number);
      const length = wholeLength(stop);
      return {
        digits,
        visible: digits.map((digit, place) => (place < WHOLE ? place >= WHOLE - length : place - WHOLE < stop.decimals)),
        negative: stop.value < 0 && scaled(stop) > 0,
        point: stop.decimals > 0,
        value: stop.value,
      };
    };
    const EMPTY = { digits: Array(PLACES).fill(0), visible: Array(PLACES).fill(false), negative: false, point: false, value: null };

    const make = (tag, part, text) => {
      const el = document.createElement(tag);
      el.className = `kodza-scroll-gauge__${part}`;
      if (text != null) el.textContent = text;
      return el;
    };

    // The dial, on a rail of no height pinned to the bottom of the screen with position: sticky:
    // it rides along while the story scrolls and leaves with the end of it
    const rail = make('div', 'rail');
    const dial = make('div', 'dial');
    dial.setAttribute('aria-hidden', 'true');
    const sr = make('span', 'sr'); // what the dial says, for screen readers
    rail.append(dial, sr);
    if (label) {
      const row = make('span', 'label');
      row.append(make('span', 'in', label));
      dial.append(row);
    }
    const reading = make('span', 'reading');
    const figure = make('span', 'figure');
    reading.append(figure);
    if (unit) {
      const box = make('span', 'unit');
      box.append(make('span', 'in', unit));
      reading.append(box);
    }
    dial.append(reading);

    // The slots, left to right: sign, whole digits (with their thousands separators), decimal
    // point, decimals. A digit spins in its window; an empty slot closes to no width
    const slots = [];
    const digitSlots = [];
    const addChar = (kind, char, place) => {
      const el = make('span', 'char', char);
      figure.append(el);
      slots.push({ el, kind, place });
    };
    if (stops.some((stop) => stop.value < 0)) addChar('sign', '−');
    for (let place = 0; place < PLACES; place += 1) {
      if (place === WHOLE) addChar('point', decimalChar);
      const el = make('span', 'digit');
      const strip = make('span', 'strip');
      strip.append(make('span', 'cell', ''));
      el.append(strip);
      figure.append(el);
      const slot = { el, kind: 'digit', place, strip, anim: null };
      slots.push(slot);
      digitSlots.push(slot);
      if (grouping && place < WHOLE - 1 && (WHOLE - 1 - place) % 3 === 0) addChar('group', groupChar, place);
    }

    const notes = stops.some((stop) => stop.note) ? stops.map((stop) => make('span', 'line', stop.note)) : [];
    if (notes.length) {
      const row = make('span', 'note');
      row.append(...notes);
      dial.append(row);
    }

    // The scale of the whole story, from its lowest value to its highest: a tick for each section,
    // and the needle on the one being read
    const values = stops.map((stop) => stop.value);
    const low = Math.min(...values);
    const high = Math.max(...values);
    const at = (v) => (high > low ? (v - low) / (high - low) : 0.5);
    const scale = make('span', 'scale');
    scale.append(make('span', 'track'));
    stops.forEach((stop) => {
      const tick = make('span', 'stop');
      tick.style.left = `calc(${at(stop.value).toFixed(4)} * (100% - 1px))`;
      scale.append(tick);
    });
    const needle = make('span', 'needle');
    needle.append(make('span', 'tick'));
    scale.append(needle);
    dial.append(scale);
    root.append(rail);

    // The width of each kind of slot, in em of the figure, measured in the page's own font
    const ems = { digit: 0.62, sign: 0.6, point: 0.28, group: 0.28 };
    let measured = false;
    const measure = () => {
      const probe = make('span', 'probe');
      figure.append(probe);
      const size = parseFloat(getComputedStyle(figure).fontSize) || 0;
      const widthOf = (text) => {
        probe.textContent = text.repeat(10);
        return probe.offsetWidth / 10 / size;
      };
      const digit = size ? Math.max(...'0123456789'.split('').map(widthOf)) : 0;
      if (digit > 0) {
        Object.assign(ems, { digit, sign: widthOf('−'), point: widthOf(decimalChar), group: widthOf(groupChar) });
        measured = true;
      }
      probe.remove();
    };
    const open = (slot, shape) => {
      if (slot.kind === 'sign') return shape.negative;
      if (slot.kind === 'point') return shape.point;
      return shape.visible[slot.place];
    };
    // animate: false sets the widths at once (the dial coming in, the font loading)
    const size = (shape, animate) => {
      slots.forEach((slot) => {
        if (!animate) slot.el.style.transition = 'none';
        const shown = open(slot, shape);
        slot.el.style.width = `${shown ? ems[slot.kind].toFixed(4) : 0}em`;
        slot.el.classList.toggle('is-closed', !shown);
      });
      if (animate) return;
      void figure.offsetWidth;
      slots.forEach((slot) => {
        slot.el.style.transition = '';
      });
    };

    let shape = EMPTY; // what the figure shows, EMPTY while the dial is away
    let current = -1; // the section on the dial, -1 before the first one

    // The digit a slot shows right now, and how far past it: a roll cut short by the next one
    // starts again from there, nothing jumps
    const cellOf = (slot) => {
      if (slot.anim?.playState !== 'running') return null;
      const cells = slot.strip.children;
      const height = parseFloat(getComputedStyle(cells[0]).height) || 1;
      const pos = -new DOMMatrixReadOnly(getComputedStyle(slot.strip).transform).m42 / height;
      const index = Math.min(cells.length - 1, Math.max(0, Math.round(pos)));
      const text = cells[index].textContent;
      return { digit: text === '' ? 0 : Number(text), blank: text === '', offset: pos - index };
    };

    const rollTo = (stop, animate) => {
      const to = shapeOf(stop);
      const from = shape;
      const up = from.value === null || stop.value >= from.value;
      const now = digitSlots.map((slot) => (from.value !== null && cellOf(slot)) || { digit: from.digits[slot.place], blank: !from.visible[slot.place], offset: 0 });
      // The highest digit that changes rolls straight to its value; the ones on its right spin
      // 1 to TURNS full turns more and land later, the ones on its left stay put
      const first = now.findIndex((cell, i) => cell.digit !== to.digits[i] || cell.blank === to.visible[i]);
      let last = -1;
      now.forEach((cell, i) => {
        if (!cell.blank || to.visible[i]) last = i;
      });
      digitSlots.forEach((slot, i) => {
        const cell = now[i];
        const blank = !to.visible[i];
        let steps = 0;
        if (first >= 0 && i >= first && !(cell.blank && blank)) {
          steps = ((((up ? to.digits[i] - cell.digit : cell.digit - to.digits[i]) % 10) + 10) % 10);
          if (i > first) steps += 10 * (last - first > 1 ? 1 + Math.round(((i - first - 1) / (last - first - 1)) * (TURNS - 1)) : 1);
        }
        // The cells from the digit shown to the new one, in the direction of the value: the
        // strip goes up when it climbs (new digits from below), down when it falls (from above)
        let texts = [blank ? '' : String(to.digits[i])];
        if (steps) {
          texts = [];
          for (let s = 0; s <= steps; s += 1) texts.push(String((((up ? cell.digit + s : cell.digit - s) % 10) + 10) % 10));
          if (cell.blank) texts[0] = '';
          if (blank) texts[steps] = '';
          if (!up) texts.reverse();
        }
        const end = up ? steps : 0;
        // Cut short, a roll carries on from where it was, when that cell has a neighbour
        const offset = steps && (up ? cell.offset > 0 : cell.offset < 0) ? cell.offset : 0;
        const start = (up ? 0 : steps) + offset;
        slot.anim?.cancel();
        slot.anim = null;
        slot.strip.replaceChildren(...texts.map((text) => make('span', 'cell', text)));
        slot.strip.style.transform = `translateY(${(-end * CELL).toFixed(3)}em)`;
        if (!animate || start === end) return;
        slot.anim = slot.strip.animate(
          [{ transform: `translateY(${(-start * CELL).toFixed(3)}em)` }, { transform: `translateY(${(-end * CELL).toFixed(3)}em)` }],
          { duration: (ROLL + Math.max(0, i - first) * LAG) * pace, easing: EASE },
        );
      });
      size(to, animate);
      shape = to;
    };

    // The needle: from where it is, even halfway through a slide
    const point = (to, from, animate) => {
      const target = `translateX(${(at(to) * 100).toFixed(2)}%)`;
      const before = needle.getAnimations().length ? getComputedStyle(needle).transform : from;
      needle.getAnimations().forEach((anim) => anim.cancel());
      needle.style.transform = target;
      if (animate) needle.animate([{ transform: before }, { transform: target }], { duration: ROLL * pace, easing: EASE });
    };

    // The note rolls like a word: the old one leaves on the side you scroll from, the new one
    // comes in from the side you scroll to
    const note = (index, dir, animate) => {
      notes.forEach((line, i) => {
        const on = i === index;
        if (line.classList.contains('is-current') === on) return;
        const before = line.getAnimations().length ? getComputedStyle(line).transform : null;
        line.getAnimations().forEach((anim) => anim.cancel());
        // The class gives the resting place, the animation the way there
        line.classList.toggle('is-current', on);
        if (!animate) return;
        line.animate(
          [{ transform: before || (on ? `translateY(${dir * 110}%)` : 'none') }, { transform: on ? 'none' : `translateY(${-dir * 110}%)` }],
          { duration: NOTE * pace, easing: NOTE_EASE },
        );
      });
    };

    const show = (index) => {
      const stop = stops[index];
      if (current < 0) {
        // The dial comes in from its corner: the figure rolls up from nothing, the needle sweeps
        // from the start of the scale, the note rises with the label
        if (!measured) measure();
        shape = EMPTY;
        size(EMPTY, false);
        rollTo(stop, !still);
        notes.forEach((line) => line.classList.remove('is-current'));
        note(index, 1, !still);
        point(stop.value, 'translateX(0%)', !still);
        root.classList.add('is-shown');
      } else {
        rollTo(stop, !still);
        note(index, index > current ? 1 : -1, !still);
        point(stop.value, needle.style.transform, !still);
      }
      current = index;
      sr.textContent = `${[label, spoken(stop), unit].filter(Boolean).join(' ')}${stop.note ? `, ${stop.note}` : ''}`;
    };
    const hide = () => {
      current = -1;
      root.classList.remove('is-shown');
      sr.textContent = '';
    };

    let frame = 0;
    const read = () => {
      frame = 0;
      const line = window.innerHeight * (window.innerHeight <= 720 ? LINE_SHORT : LINE);
      let index = -1;
      stops.forEach((stop, i) => {
        if (stop.el.getBoundingClientRect().top <= line) index = i;
      });
      if (index === current) return;
      if (index < 0) hide();
      else show(index);
    };
    const schedule = () => {
      if (!frame) frame = requestAnimationFrame(read);
    };

    measure();
    size(EMPTY, false);
    document.fonts?.ready.then(() => {
      if (signal.aborted) return;
      measure();
      size(shape, false);
    });
    // Scrolling anywhere: the page, or a box the story scrolls in
    document.addEventListener('scroll', schedule, { capture: true, passive: true, signal });
    window.addEventListener('resize', schedule, { signal });
    signal.addEventListener('abort', () => cancelAnimationFrame(frame));
    schedule();
  }

  // Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
  // event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
  // markup back. For themes and apps that swap content without a page load. Each running root
  // keeps its markup as written under KODZA, shared by every Kodza script on the page: a Kodza
  // component inside another one is saved as written, not half-started, and stopped with it. Two
  // components on one root (a reveal on a stat card) both start, and stop together.
  const KODZA = Symbol.for('kodza');
  const RUNNING = Symbol.for(`kodza ${SELECTOR}`); // a root this component runs on, for every copy of this script
  const instances = new WeakMap();
  const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
  const attrsOf = (el) => [...el.attributes].map((a) => [a.name, a.value]);
  const put = (el, saved) => {
    [...el.attributes].forEach((a) => el.removeAttribute(a.name));
    saved.attrs.forEach(([name, value]) => el.setAttribute(name, value));
    el.innerHTML = saved.html;
  };
  // The markup inside a root as written: Kodza components already running in it give back their own
  const written = (root) => {
    const all = [...root.querySelectorAll('*')];
    if (!all.some((el) => el[KODZA])) return root.innerHTML;
    const copy = root.cloneNode(true);
    const twins = copy.querySelectorAll('*');
    let last = null;
    all.forEach((el, i) => {
      if (!el[KODZA] || last?.contains(el)) return;
      last = el;
      put(twins[i], el[KODZA]);
    });
    return copy.innerHTML;
  };
  const init = (scope) => find(scope).forEach((root) => {
    // Already running, maybe from another copy of this script. Marked is-ready with no Kodza component
    // running on it, a root is a copy of a started one (a cloned slide): it is left as it is
    if (root[RUNNING] || (root.classList.contains('is-ready') && !root[KODZA])) return;
    // Rendered by React (data-kodza-manual): React starts it, with an init aimed at that markup once
    // it has hydrated it. Any earlier start would change markup React has not taken over yet
    const owner = root.closest('[data-kodza-manual]');
    if (owner && !(scope && owner.contains(scope))) return;
    const controller = new AbortController();
    // Another Kodza component already running on this root: its markup as written is kept, and the
    // two stop together
    const before = root[KODZA];
    const saved = { html: before ? before.html : written(root), attrs: before ? before.attrs : attrsOf(root), stop: () => destroy(root) };
    if (before) before.above = saved;
    instances.set(root, { controller, saved, before });
    root[KODZA] = saved;
    root[RUNNING] = true;
    mount(root, controller.signal);
    root.classList.add('is-ready');
  });
  const destroy = (scope) => find(scope).forEach((root) => {
    const instance = instances.get(root);
    if (!instance) return;
    instances.delete(root);
    instance.saved.above?.stop(); // a Kodza component started after it on the same root stops first
    // The Kodza components running inside it stop first: once its markup is put back, their own
    // script could not find them any more
    root.querySelectorAll('*').forEach((el) => el[KODZA]?.stop());
    instance.controller.abort();
    delete root[RUNNING];
    // Started on top of another one: that one stops next, and puts the markup back
    if (instance.before) {
      delete instance.before.above;
      root[KODZA] = instance.before;
      return instance.before.stop();
    }
    delete root[KODZA];
    put(root, instance.saved);
  });
  document.addEventListener('kodza:init', (event) => init(event.detail?.root));
  document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
  init();
  // Loaded in <head>, the script runs before the markup exists: once more when it is parsed
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
```

Free to use, from Kodza (https://kodza.dev).
