Motion
Scroll-driven animations
Limited availability
Replaces: A scroll listener and an IntersectionObserver driving classes. An animation’s progress is tied to scroll position, off the main thread.
See it working
Scroll this box. The bar is driven by the scroll position, with no listener and no JavaScript.
Keep going.
A little further.
Nearly at the end.
Done. The bar is full.
The syntax
.progress {
animation: grow linear both;
animation-timeline: scroll(nearest block);
}
@keyframes grow { from { scale: 0 1; } to { scale: 1 1; } } Edit the demo’s CSS
This is the stylesheet running the demo above. Change a value and watch it. Break it on purpose: delete the modern line and you are looking at the fallback.
For browsers without it
The animation lives inside @supports and the bar is simply full-width without it. A reading-progress bar is decoration: the page must work with it sitting still.