Scroll Progress Bar
A 4 px bar stuck to the top of a scrolling panel, filling from left to right exactly as fast as you read: 20% after 100 px, 52% after 260 px, full at the end of the 496 px travel. CSS is enough wherever animation-timeline: scroll() exists; seventeen lines of JavaScript do the same job in Firefox.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Scroll has 74 effects, including 12 free. Explore the category →
3 usage examples



How it works
The first child of the scrolling area (.sdc-scroll-container, 280 px tall) is a track, .sb-progressbar-bar, set to position: sticky; top: 0: it holds the top edge while the content slides beneath. Inside it, .sb-progressbar-fill carries the violet → pink gradient, starts at transform: scaleX(0) with transform-origin: left center, and plays @keyframes fx0547Grow up to scaleX(1). The line that matters is animation-timeline: scroll(): the animation no longer advances with time but with the position of the first scrolling ancestor — here the area, not the page. Checked with two copies on one page: scrolling the second leaves the first bar at zero.
The bar is plain proportion: width = scroll offset ÷ travel. Read in Chromium 149 and WebKit 26.5: 20.2% at 100 px, 52.4% at 260 px, 80.6% at 400 px, 100% at 496 px. Firefox 151 has no animation-timeline; there the supplied script finds each root, pauses the same animation and sets its currentTime on every scroll event: 20.1%, 52.3%, 80.5% at the same positions. The travel is written nowhere: the .sb-progressbar-content tray has no imposed height, it is as tall as what it holds (a heading, a sentence, five 120 px blocks), and the bar adjusts by itself when you add more.
Three flaws of the original code were fixed. The animation only had a to keyframe: in WebKit the bar then moved at the square of the progress — 3.6% at 100 px, 24.6% at mid-scroll, 58.3% at 400 px, where 19, 50 and 76% were expected. The starting keyframe is now spelled out and both engines give the same figures. The tray was a fixed 800 px for 636 px of content: the bar finished its run over 164 px of nothing. And the selectors now hang from .fx-0547-root, with animations renamed fx0547…: several effects in the catalogue share the .sdc-scroll-container and .sdc-scroll-hint classes, and they no longer overwrite one another.
Accessibility
- Screen readers: the track and its fill are two empty
divs markedaria-hidden="true". That is deliberate: CSS cannot publish a value, and arole="progressbar"without an up-to-datearia-valuenowwould announce something false. If progress has to be spoken, a script must readscrollTop— this code has none. The area itself is a namedregion(rewrite thearia-label). - Keyboard:
tabindex="0"makes the area reachable with Tab in Chromium, Firefox and WebKit — the last one skipped it in the original code. Focus shows (2 px violet outline, 7.3:1 against the background), then arrow keys, Space and Page Down scroll; the bar follows as it does with the wheel (four arrow presses = 160 px = 32% in Chromium). - Reduced motion: the bar is kept under
prefers-reduced-motion: reduce. It only moves when the reader scrolls and it answers that gesture: it is a marker, not decorative animation. What is removed: the pulsing of the “Scroll” hint and the area'sscroll-behavior: smooth. To hide the bar anyway, onedisplay: nonerule on.sb-progressbar-barinside that same query is enough. - Contrast and touch: the fill reaches 4.7:1 at its violet end and 5.6:1 at its pink end against
#0a0a0f(computed), above the 3:1 asked of a graphic element. The empty track, white at 10%, is nearly invisible (1.25:1): until something has scrolled, nothing suggests a bar is there. With a finger the area scrolls natively (a 150 px swipe read as 151 px in touch emulation) and 4 px is not a target: the bar is shown, never handled.
Browser compatibility
animation-timeline: scroll(): Chrome and Edge 115, Safari 26, Firefox 159 according to MDN. Below that the script drives the bar; it needs Element.getAnimations() (Firefox 75, Safari 13.1). Measured: the CSS route in Chromium 149 and WebKit 26.5, the JavaScript route in Firefox 151, no console error. position: sticky has been safe everywhere for years. Not tried: Firefox 159 and later, a real Safari, a real phone.
Two safety nets, in this order. If the browser ignores animation-timeline, the @supports block is skipped and the script takes over (it steps aside by itself as soon as the property is recognised). If the script is missing or blocked too, the fill stays at scaleX(0): an empty 4 px track at the top of the panel, with no error and nothing hidden.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0547-root">
<div class="sdc-scroll-container" tabindex="0" role="region" aria-label="…">
<div class="sb-progressbar-bar" aria-hidden="true">
<div class="sb-progressbar-fill"></div>
</div>
<div class="sb-progressbar-content">
<h4>…</h4>
<p>…</p>
<div class="sb-progressbar-block"></div>
… ×5
</div>
</div>
<span class="sdc-scroll-hint" aria-hidden="true">…</span>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Thickness (CSS — .sb-progressbar-bar { height: 4px }) |
4 px | 2 px for a discreet hairline above a text, 8 to 10 px for a screen read from a distance. The fill takes the full height of the track. |
Colours (CSS — .sb-progressbar-fill { background }, .sb-progressbar-bar { background }) |
gradient #8b5cf6 → #ec4899 over white at 10% | A solid colour reads better over 4 px than a gradient. Raise the track to about 25% white if it must be seen before the first scroll. |
Direction (CSS — transform-origin: left center) |
left to right | right center fills from the right (pages in Arabic or Hebrew); center opens the bar from the middle. |
What the bar measures (CSS — animation-timeline: scroll()) |
the nearest scrolling area, top to bottom | scroll(root) follows the whole page; scroll(inline) follows a horizontal scroll. In both cases the fallback script still listens to .sdc-scroll-container: adapt it as well. |
Panel height (CSS — .sdc-scroll-container { height: 280px }) |
280 px | Any height, or a fluid one (60vh). The travel, and so the filling speed, recomputes by itself. |
Hint (HTML — span.sdc-scroll-hint) |
“Scroll ↓” over the bottom of the frame | A demo prop: delete the element and the fx0547HintPulse rule once the panel holds your own content. |
FAQ
scroll(), the same fallback script — and it is free. What this version adds is finish: an area reachable by keyboard in Safari with a name for screen readers, a reduced-motion setting, selectors hung from the root, a tray that follows its content instead of a fixed 800 px. If Progress Bar is already in your project, this one will not change the look.position: fixed; top: 0; left: 0, then write animation-timeline: scroll(root) on the fill. For Firefox, replace the area with document.documentElement in the script and listen to scroll on window. The shipped version targets a panel on purpose: that is the case most reading bars do not cover.scrollTop, scrollHeight and clientHeight in JavaScript — three lines, which we do not ship here so that the bar stays in CSS.