Scroll this panel
The bar at the top of this box is not measuring the page. It is bound to this element's own scroll container, using animation-timeline: scroll(nearest block). Scroll to the bottom and it reaches exactly full width at the last pixel.
Why scaleX and not width
Animating width changes the geometry of the element, so the browser re-runs layout for the bar and everything that depends on it. Animating transform: scaleX() leaves geometry untouched and runs on the compositor.
One consequence: a scaled border or radius distorts. A progress bar has neither, which is exactly why the substitution is safe here and unsafe on, say, a card.
Where the number comes from
The timeline maps scroll offset to progress with no rounding you have to manage. When the container has no scrollable overflow the animation sits at its start value, so a short article simply shows an empty bar rather than a full one.
That behaviour is worth keeping. A full bar on an unscrollable page implies the reader has finished something they never started.
The fallback is one condition
Firefox has supported this since version 144; anything older needs the JavaScript path. The check is a single CSS.supports call, and the fallback reads scroll position inside a requestAnimationFrame callback rather than on the event itself.
Reading layout inside a scroll handler is what makes the naive version stutter: the handler runs many times per frame, each read forces a style recalculation, and the writes queue up behind it.
End of the panel
The bar should now be at one hundred percent. Scroll back up and it unwinds in reverse — there is no state to reset, because the animation is a pure function of scroll offset.