How to Show Reading Progress with a CSS Bar at the Top of the Page
A reading progress bar at the top of the screen, showing how far the reader has got through the page, can be built with only animation-timeline: scroll() in CSS. You define an animation that stretches the bar horizontally and tie its progress to the page's scroll amount instead of time. No JavaScript is needed to calculate the scroll amount.
The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I opened an HTML and CSS page with Playwright and read the computed transform value of the bar at each scroll position. I did not test Firefox, Safari, or real smartphones.

The CSS and HTML for the bar
In the HTML, place one empty div to serve as the bar. Since it has no content and is only decoration, it has aria-hidden="true".
<body>
<div class="reading-progress" aria-hidden="true"></div>
<header>サイトのヘッダー</header>
<main>
<!-- Body text -->
</main>
<footer>サイトのフッター</footer>
</body>
The CSS is as follows.
/* Show how much of the page has been read using the bar at the top of the screen */
@supports (animation-timeline: scroll()) {
.reading-progress {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 6px;
background: #00c8e8;
transform-origin: 0 50%;
/* On pages that cannot scroll, the timeline does not work and the value stays the same */
transform: scaleX(0);
z-index: 10;
animation: reading-progress 1ms linear both;
animation-timeline: scroll(root block);
}
}
@keyframes reading-progress {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
The bar is fixed to the top edge of the screen with position: fixed, and its width is set to fill the screen. Its length is changed with transform: scaleX() rather than width. An animation in @keyframes stretches it from scaleX(0) to scaleX(1), and animation-timeline ties the animation's progress to scrolling.
transform-origin: 0 50% is there so the bar grows from the left edge. The initial value of transform-origin is 50% 50% (the center of the element), so without this line the bar would expand left and right from the middle.
The 1ms in the animation shorthand is not the playback duration. According to MDN's explanation of scroll-driven animation timelines, for animations tied to scrolling, animation-duration does not affect playback time. However, Firefox does not apply the animation unless a non-zero value is given, so writing 1ms is the common practice.
Also, as noted on MDN's animation-timeline page, the animation shorthand resets animation-timeline to auto. Write animation-timeline after animation.
scroll(root block): following the scroll amount of the whole page
scroll() is a function that chooses which element's scrolling is used, and whether the vertical or horizontal scroll is used. root selects the document's root element, meaning the scrolling of the whole page. block means the vertical direction on a horizontal-writing page.
On a screen 400px wide and 800px high, I read the values at each scroll position. The bar's length matched the ratio of the scrolled amount to the total scrollable amount. The total scrollable amount on this page is 3329px.
scrollY=0 最大=3329 scaleX=0.000 幅=0.0px
scrollY=832 最大=3329 scaleX=0.250 幅=100.0px
scrollY=1665 最大=3329 scaleX=0.500 幅=200.1px
scrollY=2497 最大=3329 scaleX=0.750 幅=300.0px
scrollY=3329 最大=3329 scaleX=1.000 幅=400.0px
If you omit the argument to scroll(), it means the same as scroll(nearest block), which uses the nearest ancestor scroll container. On this page, animation-timeline: scroll() gave exactly the same values at all five positions. Still, writing root makes it clear from the code that the scrolling of the whole page is used.
Because the bar follows the scroll amount of the whole page, it includes the footer below the body. On this page, which has a 300px-tall footer, the bar was at 91.0% when the end of the body reached the bottom of the screen. It reaches 100% once you have scrolled all the way to the footer.
The bar reaches 100% only when you scroll to the very bottom of the page. It shows how far you have progressed through the whole page, not the point where you finished reading the body text.
On a page that cannot scroll, the bar stretches to the edge
When the page fits on the screen and cannot scroll, the timeline does not work. MDN's scroll() page also states that if there is no scrollbar on the specified axis, the animation's timeline is inactive.
In the test environment, when the timeline was inactive, the transform specified directly on the element was used instead of the animation value. If no transform was written, the computed value was none, and the bar stayed stretched across the full screen width. The transform: scaleX(0) in the CSS above is there to prevent this. With it written, the width became 0 on a page that could not scroll, and the bar was not visible.
transform を書かない場合: 最大=0 scaleX=none(1) 幅=400.0px
transform: scaleX(0) を書いた場合: 最大=0 scaleX=0.000 幅=0.0px

On browsers that do not support it, the bar is not shown
In the CSS above, all the bar's styles are written inside @supports. In a browser that does not support animation-timeline: scroll(), the bar becomes an empty div with no styling and is invisible.
I did not have a browser that lacks support in the test environment, so I deliberately changed the @supports condition to something that is never true (animation-timeline: no-such-value) to check this. In that case, the bar div had position set to static, a height of 0px, and a transparent background, and nothing changed when I scrolled.
I also checked the case where the rules are written without @supports. When I made the animation-timeline value invalid (no-such-value), so that this declaration is not used, the computed value became auto. According to MDN's animation-timeline page, auto is the document timeline, which advances with time. This animation ends after 1ms and stays at scaleX(1), so the bar remained stretched across the full screen width regardless of scroll position.
Showing how much has been read inside a scrolling box
To show how much has been read inside a scrolling box within the page, such as a terms-of-service box, use scroll() with no arguments. When the bar is placed inside the box, it follows the scrolling of the nearest ancestor scroll container, which is the box.
<div class="terms" tabindex="0">
<div class="terms-progress" aria-hidden="true"></div>
<p>第1条 …</p>
</div>
/* Within a scrollable frame, show how much has been read using the bar at the top of the frame */
.terms {
height: 240px;
overflow-y: auto;
border: 1px solid #9aa5ab;
}
@supports (animation-timeline: scroll()) {
.terms-progress {
position: sticky;
top: 0;
height: 4px;
background: #00c8e8;
transform-origin: 0 50%;
transform: scaleX(0);
animation: reading-progress 1ms linear both;
/* Use the nearest ancestor scroll container (.terms) as the reference */
animation-timeline: scroll();
}
}
The @keyframes is the same as for the whole-page bar. Inside the box, position: sticky with top: 0 is used instead of position: fixed, so that the bar stays at the top edge of the box even as the box scrolls.

As the box was scrolled, the bar stretched in proportion to the box's scrollable amount. The bar stayed at the top edge of the box (1px inside the border) at every scroll position.
枠のscrollTop=0 枠の最大=284 scaleX=0.000
枠のscrollTop=142 枠の最大=284 scaleX=0.500
枠のscrollTop=284 枠の最大=284 scaleX=1.000
If you write scroll(root) here, the bar follows the scrolling of the whole page instead of the box. When I tried it, the bar stayed at 0 even after scrolling the box to the end, and it reached 39.3% when I scrolled the page itself by 300px.
Supported browsers
According to MDN's compatibility data (@mdn/browser-compat-data 8.1.8), animation-timeline and scroll() are both available from the following versions.
| Browser | Version |
|---|---|
| Chrome, Edge | 115 |
| Firefox | 159 |
| Safari (macOS, iOS) | 26 |
The same data gives the release date of Firefox 159 as October 27, 2026. In browsers older than this, the content inside @supports is not used, so the bar is not shown.





