Scroll-Driven Animations: scroll(), view() and Animation Ranges
Animations driven by scrolling: animation-timeline with scroll() and view(), animation-range with cover, entry, exit and contain, named timelines and timeline-scope, the shorthand-order trap, progress bars and reveal effects, and fallbacks.
kvi5hnuCode Sprout team member7 min readOn this page
A normal animation progresses with time. A scroll-driven animation progresses with scrolling: at the top of the page it's at 0%, at the bottom 100%, and it moves backward when you scroll back. Reading-progress bars, headers that shrink as you scroll, and elements that fade in as they enter the viewport used to need JavaScript scroll listeners; now they're a few lines of CSS that run off the main thread.
@keyframes grow { from { scale: 0 1; } }
.progress {
position: fixed; inset: 0 0 auto; block-size: 4px; background: #8a3b12;
transform-origin: left;
animation: grow linear both;
animation-timeline: scroll(); /* the page's scroll position drives it */
}
Scroll-driven animations work in Chrome 115, Safari 26 and Firefox 159.
animation-timeline
animation-timeline replaces the default time-based timeline, auto, with a scroll-based one. There are two kinds.
Scroll progress timelines: scroll()
scroll(<scroller> <axis>) tracks how far a scroll container has been scrolled, from 0% at the start to 100% at the end:
| Argument | Values | Default |
|---|---|---|
| scroller | nearest (the nearest ancestor scroll container), root (the page), self | nearest |
| axis | block, inline, y, x | block |
Tested in Chrome, with a scroll container 200px tall and 1200px of content, so 1000px of scrolling: a width animation from 0 to 100px with scroll(nearest block) was 25px at a scroll position of 250px, 50px at 500px and 100px at 1000px.
View progress timelines: view()
view(<axis> <inset>) tracks an element's own visibility in its scroll container: 0% when it starts to enter from the bottom edge, 100% when it has completely left through the top. That's what you need for effects as elements come into view:
@keyframes reveal { from { opacity: 0; translate: 0 2rem; } }
.card {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%; /* only while it's entering */
}
The inset, like view(block 20% 0%), shrinks or grows the area that counts as visible: the first value insets the start edge (the top, for block), the second the end edge. Use it, for example, to ignore a sticky header.
animation-range

By default, an animation uses the whole timeline. animation-range limits it to part of it, with a start and an end. For view timelines, named ranges describe the element's position:
| Range | From | To |
|---|---|---|
cover (default) | the element's first edge enters | its last edge leaves |
entry | it starts entering | it's fully inside |
exit | it starts leaving | it's fully gone |
contain | it's fully inside | it starts leaving (if taller than the scrollport: while it fills it) |
entry-crossing, exit-crossing | its edge crosses the end or start edge | its other edge does |
Each end of the range is a name with an optional percentage, or a length or percentage of the whole timeline:
.hero-img { animation-range: exit 0% exit 100%; } /* while it scrolls away */
.badge { animation-range: entry 25% cover 50%; } /* from a quarter entered to the middle */
.header { animation-range: 0 200px; } /* scroll(): the first 200px of scrolling */
Tested in Chrome, a 100px element in a 200px scrollport was 40% through its animation with animation-range: entry 0% entry 100% when 40px of it had entered, and a full-range view() animation was 63% through when the element was a little above the middle. The computed value of animation-range: entry 0% entry 100% was simply entry.
animation-range-start and animation-range-end are the longhands. Keyframes can also name ranges directly: @keyframes fade { entry 0% { opacity: 0 } entry 100% { opacity: 1 } }. Tested in Chrome, a width animated that way was at 40% when 40% of the element had entered. But the rest of the timeline still belongs to the animation: after the entry range, the value moved back toward the element's own width, toward the implicit 100% keyframe. Add animation-range: entry to stop there.

The readouts show the scroll() timeline exactly tracking the scroll position. At 75%, the bottom card is only partly inside the box, so its entry range, and its fade, are only partly done.
Named timelines
scroll() and view() only find the nearest scroller or the element itself. To animate another element, name a timeline and refer to it:
.gallery { overflow-x: auto; scroll-timeline: --gallery inline; } /* name and axis */
.gallery-progress { animation: grow linear both; animation-timeline: --gallery; }
scroll-timeline: <name> <axis>on a scroll container creates a scroll progress timeline.view-timeline: <name> <axis>on any element creates a view progress timeline for it.- Names are dashed idents, like custom properties.
By default, a named timeline is visible only to the element's descendants. timeline-scope on a shared ancestor makes it visible to the rest of that ancestor's subtree, such as a sibling of the scroller:
.layout { timeline-scope: --gallery; } /* .gallery and .gallery-progress are both inside */
Tested in Chrome: an element outside the scroller, with timeline-scope on their shared parent, was at 50% when the named scroller was halfway.
Gotchas
- Write
animation-timelineafter theanimationshorthand. The shorthand resetsanimation-timelinetoauto. Tested in Chrome: withanimation-timeline: scroll()followed byanimation: grow 1s linear both, the timeline computed toauto, and the element animated over time instead of with scrolling. - The duration doesn't matter: progress comes from scrolling. Leave it out; the default
autofills the timeline. Tested in Chrome, the computed duration wasauto. - Use
lineareasing, so the animation tracks the scroll position directly, andbothfill, so the start and end states hold outside the range. overflow: hiddenon an ancestor can turn it into the nearest scroll container, and the timeline then tracks a container that never scrolls.- If there's nothing to scroll, the timeline is inactive and the animation shows no effect.
- Animations of
transformandopacityrun on the compositor, so scroll-driven effects stay smooth even when JavaScript is busy (article 111).
Fallbacks and accessibility
Wrap scroll-driven effects in @supports, so older browsers show the final, usable state:
@supports (animation-timeline: view()) {
@media (prefers-reduced-motion: no-preference) {
.card { animation: reveal linear both; animation-timeline: view(); animation-range: entry; }
}
}
Never hide content until it's scrolled into view without such guards: in a browser without support, a from { opacity: 0 } keyframe that never runs is harmless, but content hidden by default would stay hidden. Scroll-linked motion like parallax is exactly what affects people with vestibular disorders, so put it under prefers-reduced-motion: no-preference (article 112).
Chrome 146 adds scroll-triggered animations (animation-trigger and timeline-trigger), which start a normal time-based animation when an element reaches a scroll position, instead of tying progress to scrolling. They're Chromium-only so far.
body { font: 0.85rem system-ui, sans-serif; margin: 1rem; }
.reader { block-size: 16rem; overflow-y: auto; border: 2px solid #d8cfc0; border-radius: 8px; padding: 0 0.8rem 0.8rem; }
.progress {
position: sticky; inset-block-start: 0; block-size: 5px; margin-inline: -0.8rem;
background: #8a3b12; transform-origin: left;
}
.title { margin: 0.6rem 0 0.3rem; }
.card { margin-block: 0.8rem; padding: 1.2rem 0.8rem; border-radius: 8px; color: white; background: #1d3557; }
@keyframes grow { from { scale: 0 1; } }
@keyframes reveal { from { opacity: 0; translate: 0 1.5rem; scale: 0.95; } }
@supports (animation-timeline: scroll()) {
@media (prefers-reduced-motion: no-preference) {
.progress { animation: grow linear both; animation-timeline: scroll(nearest block); }
.card { animation: reveal linear both; animation-timeline: view(); animation-range: entry 0% entry 90%; }
}
}
The bar is a scroll() timeline of the box, and each card has its own view() timeline, limited to its entry range, so it finishes fading in just before it's fully visible. Scroll back up and the cards fade out again: progress follows the scroll position in both directions.
What's current
animation-timeline,scroll(),view(),animation-rangeand named timelines: Chrome 115, Safari 26, Firefox 159;timeline-scopearrived a version later in Chrome, 116.- Scroll-triggered animations: Chrome 146 only.
Common questions
Why does my scroll-driven animation run over time instead?
animation-timeline was written before the animation shorthand, which reset it. Put it after.
Why doesn't my animation move at all?
The nearest scroll container may not scroll, or there's nothing to scroll. Name the timeline on the right scroller, or use scroll(root).
How do I animate a sibling of the scroller?
Name the scroller's timeline with scroll-timeline, and put timeline-scope on a shared ancestor.
Do I need a duration?
No. Leave it as auto.
Summary
animation-timeline: scroll()ties progress to a scroller's position;view()to an element's visibility.animation-rangelimits the animation to part of the timeline:cover,entry,exit,contain, or offsets.- Named timelines with
scroll-timelineandview-timeline, plustimeline-scope, let other elements use them. - Write
animation-timelineafter theanimationshorthand, uselinearandboth, and skip the duration. - Guard with
@supportsandprefers-reduced-motion, and never leave content hidden without support.
Practice questions
Write a reading-progress bar for the whole page.
Answer
@keyframes grow { from { scale: 0 1; } }
.progress {
position: fixed; inset: 0 0 auto; block-size: 4px; background: currentColor;
transform-origin: left;
animation: grow linear both;
animation-timeline: scroll(root);
}
Images should fade in only while they enter the viewport, and stay fully visible after. Write the animation properties.
Answer
@keyframes fade-in { from { opacity: 0; } }
img { animation: fade-in linear both; animation-timeline: view(); animation-range: entry 0% entry 100%; }
both keeps the final state once the range has passed.
What's wrong with this rule?
.bar { animation-timeline: scroll(); animation: grow linear both; }
Answer
The animation shorthand resets animation-timeline to auto, so the bar animates over time (with a zero duration, instantly). Write animation-timeline after the shorthand.
A progress indicator is a sibling of a horizontally scrolling gallery. How can it follow the gallery's scroll?
Answer
.gallery { overflow-x: auto; scroll-timeline: --gallery inline; }
.wrapper { timeline-scope: --gallery; } /* shared ancestor */
.indicator { animation: grow linear both; animation-timeline: --gallery; }
Previous: Accessible Motion: prefers-reduced-motion and Meaningful Animation
Next: View Transitions: Animating Between Page States and Between Pages

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.