Remember the flipbook from the first lesson? An ordinary animation flips its pages at a fixed speed, following the clock. What if your thumb did the flipping? Move your thumb slowly, and the picture moves slowly. Move it back, and the picture runs backwards. Stop, and the picture stays still. That is a scroll-driven animation: a CSS animation that moves forward and back with the scroll position, not with the clock. The thumb in this picture is your scrolling: the further the page is scrolled, the further the animation goes.
Timeline: the clock replaced by the scroll position
Every animation runs on a timeline: the measure that decides how far the animation has gone. The default is the document's time, second after second since the page opened. The animation-timeline property replaces it with the scroll position of a scroller, an element that can scroll: the page itself, or a box with overflow: auto. There are two scroll timelines:
| Timeline | Progress 0% | Progress 100% | Example on Mrs. Sri's page |
|---|---|---|---|
scroll() |
scroller at the very top | scroller at the very bottom | the reading progress bar |
view() |
the element starts entering the visible area | the element has fully left | the room cards appearing |
On a scroll timeline, the progress of the animation is a percentage, not seconds. So the duration is written auto, or not written at all. If you read it from JavaScript, animation.currentTime (the animation's current position) is a percentage too, such as 48.76%.
The reading progress bar with scroll()
A reading progress bar is a thin line at the top of the page that grows as you read down. Here is its CSS:
@keyframes grow {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
.progress {
position: sticky;
top: 0;
height: 4px;
background: #15803d;
transform-origin: 0 50%; /* grow from the left */
animation: grow linear both;
animation-timeline: scroll(); /* must come AFTER the animation shorthand */
}
scroll()is the same asscroll(nearest block).nearestmeans the nearest scroller that contains this element, andblockmeans the vertical direction.scroll(root)always uses the page.linearmakes the bar follow the scroll exactly. Withease, the bar is already at 41% when the scroll is only at 25% (we measured), so the bar feels ahead of the scroll.bothholds the start value before the animation begins, and the end value after it ends.
Our measurements in Chromium 147 and WebKit 26.4, with a 300 px scroller:
| Scroll position | Bar scaleX |
|---|---|
| 0% | 0 |
| 25% | 0.25 |
| 50% | 0.5 |
| 100% | 1 |
animation-timeline must be written after animation. The reason: the animation shorthand resets animation-timeline to auto, which is the ordinary clock. With the order reversed, the animation runs on the clock, and its duration is 0 seconds because none is written. The result: the bar is full at every scroll position (we saw it ourselves in Chromium and WebKit).
Room cards appearing with view() and animation-range
The room card enters with the same motion as in the first lesson: from see-through and 16 px lower, to its place.
@keyframes card-in {
from { opacity: 0; transform: translateY(16px); }
to { opacity: 1; transform: none; }
}
.room {
animation: card-in linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}
view() makes a timeline for the element itself, while that element travels through the scroller's visible area. animation-range picks which part of that journey plays the animation:
| Range | Starts | Ends |
|---|---|---|
entry 0% entry 100% |
the card's top edge touches the bottom of the visible area | the card is fully in |
cover 0% cover 50% |
the card starts entering | the card is in the middle of the visible area |
contain 0% contain 100% |
the card is fully in | the card starts leaving |
exit 0% exit 100% |
the card starts leaving | the card has fully left |
The Attic Room card is 120 px tall. With entry 0% entry 100%, we measured its opacity: 0 as the card first touches the visible area, 0.25 when 30 px of the card is in, 0.5 at 60 px, and 1 at 120 px. Scroll the page back up and the card fades again, because its timeline runs backwards too. Want it to appear once and stay? That's IntersectionObserver's job, covered in the lesson Intersection Observer.
In the first lesson's animation table, the card enters in 300 ms. Here there's no duration: the scroll distance is the clock.
Running off the main thread
The progress bar used to be made with addEventListener('scroll', ...). On every scroll event, JavaScript reads scrollTop (how far the page has scrolled), then writes transform. All of that happens on the main thread. When the main thread is busy, the bar stutters with it. Remember the first lesson: an animation driven by the main thread got only 1 frame while the main thread was busy for 500 ms.
A scroll-driven animation runs no JavaScript at all. The browser itself links the scroll position to the animation. According to the Chrome team, an animation that only changes transform and opacity runs off the main thread, like a CSS transition. So keep to those two properties.
Browser support and the @supports fallback
This is MDN data as of November 2026, checked against the browsers we tested:
| Browser | animation-timeline, scroll(), view(), animation-range |
|---|---|
| Chrome, Edge | since version 115 (July 2023) |
| Safari (macOS and iOS) | since version 26 |
| Firefox | since version 159 (27 October 2026). In the Firefox 146 we tested, CSS.supports('animation-timeline: scroll()') is still false |
That's why a fallback (a backup for browsers without support) is still a must. In Firefox 146, animation-timeline is ignored. The rest of the rules becomes an ordinary animation lasting 0 seconds with both, so the animation jumps right to its end state. The result: the reading progress bar is 100% full from the moment the page opens, at every scroll position. The room cards happen to be fine: they are visible right away.
Wrap it all in @supports, so browsers without support still get a sensible page. The rules inside @supports (...) are used only by browsers that support the feature in the brackets:
.progress { display: none; } /* no support: no bar */
@supports (animation-timeline: scroll()) {
.progress {
display: block;
animation: grow linear both;
animation-timeline: scroll();
}
.room {
animation: card-in linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}
}
If the bar matters, build the fallback with JavaScript: a passive scroll listener (one that promises not to cancel the scroll), and one requestAnimationFrame per frame. The scroll progress is scrollY / max: the distance scrolled divided by the largest possible scroll distance.
if (!CSS.supports('animation-timeline: scroll()')) {
const bar = document.querySelector('.progress');
bar.style.display = 'block';
let ticking = false;
addEventListener('scroll', () => {
if (ticking) return; // an update is already waiting for a frame
ticking = true;
requestAnimationFrame(() => {
const max = document.documentElement.scrollHeight - innerHeight;
bar.style.transform = `scaleX(${scrollY / max})`;
ticking = false;
});
}, { passive: true }); // a promise not to call preventDefault()
}
To make cards appear with no scroll event at all, the API to use is IntersectionObserver: the browser tells you when an element enters the visible area.
Reduce motion
For people who turned on "Reduce motion", remove the upward movement and keep the fade. The to keyframe can be left out: the animation then ends at the card's base style, fully visible.
@keyframes card-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
.room { animation-name: card-fade; } /* no 16 px rise, only a fade */
}
⚠️ The wrong order, no fallback, and a bar that runs ahead
animation-timelinewritten beforeanimation. Theanimationshorthand resets the timeline toauto: the animation runs for 0 seconds on the clock, and the bar is full right away.- No
@supports. In a browser without support, such as Firefox before version 159, the progress bar shows 100% full all the time. - An
overflow: hiddenbetween the bar and its scroller. The element withoverflow: hiddenbecomes the nearest scroller, but it is never scrolled. In our measurements, the animation'scurrentTimewasnull, and the bar stood still. Usescroll(root)or move the bar. - Using
easefor progress. The bar runs ahead of the scroll (41% when the scroll is at 25%). For a progress bar, uselinear. - Animating
toporwidth. For properties other thantransformandopacity, the animation needs the main thread again.
TL;DR: A scroll-driven animation is a CSS animation that moves forward and back with the scroll position, not with the clock. The animation-timeline property replaces the clock with the scroll position. scroll() follows a scroller, the element being scrolled (0% at the top, 100% at the bottom), for a reading progress bar. view() follows an element's trip through the visible area, for cards that appear. animation-range picks a part of that trip: entry 0% entry 100% means from starting to enter to fully in, so a 120 px card has opacity 0.5 when 60 px are in. Write animation-timeline after animation, with duration auto, easing linear, and only transform/opacity so it runs off the main thread. Supported in Chrome 115, Safari 26 and Firefox 159. In older browsers, a bar without @supports shows full. Wrap it in @supports (animation-timeline: scroll()), then build the fallback with a passive scroll listener + requestAnimationFrame, or use IntersectionObserver to reveal elements. With "Reduce motion", remove the movement and keep the fade.
⚡ The clock replaced by the scroll position
Write:
.progress {
transform-origin: 0 50%; /* grow from the left */
animation: grow linear both;
animation-timeline: scroll(); /* must come AFTER the animation shorthand */
}
Meaning: This is a reading progress bar, a line at the top of the page that grows from the left. scroll() makes its animation (grow, from scaleX(0) to scaleX(1)) move forward and back with the scroll position, not with the clock: 0% at the very top of the page, 100% at the very bottom. No duration is written, because the progress comes from the scroll, not from seconds. The easing is linear so the bar follows the scroll exactly.
⚡ A tricky order
Guess first: what happens when animation-timeline is written before animation?
The bar is full at every scroll position. The animation shorthand resets animation-timeline to auto, which is the ordinary clock. On the clock, a duration that isn't written means 0 seconds, so the animation jumps right to its end state.
Meaning: animation-timeline is always written after animation.
⚡ Cards appearing with view()
Write:
.room {
animation: card-in linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}
Meaning: view() follows the trip of the room card (.room) itself through the visible area. animation-range: entry 0% entry 100% plays the animation card-in (the card appears while rising) from when the card starts to enter until it is fully in. A 120 px card has opacity 0.5 when 60 px of it are in, and fades again when you scroll the page back up.
⚡ Appearing once without scroll events
Meaning: Firefox has supported animation-timeline only since version 159. So wrap the scroll-driven rules in @supports (animation-timeline: scroll()), so that only browsers with support use them. To make a card appear once without listening to scroll events, use IntersectionObserver: the browser tells you when an element enters the visible area.