· 6 min read
CSS scroll-driven animations: scroll() and view() explained
CSS scroll-driven animations are now Baseline. Learn scroll() and view() timelines, animation-range and the shorthand trap that silently breaks them.

CSS scroll-driven animations let you tie a normal CSS animation to scroll position instead of time, so a progress bar fills as the page scrolls or a card fades in as it enters the viewport, with no JavaScript and no scroll listeners. With Firefox 159 turning them on by default in October 2026, they are now Baseline: supported in current Chrome, Edge, Safari and Firefox.
You write the @keyframes you already know, then set animation-timeline to scroll() or view(). The browser maps scroll progress to animation progress, and it can run the result off the main thread.
What are CSS scroll-driven animations?
A regular CSS animation runs on the document timeline, which is just wall-clock time since the page loaded. A timeline in this context is anything that produces a progress value from 0% to 100%, and the animation's keyframes are sampled at that progress.
Scroll-driven animations add two new kinds of timeline:
- A scroll progress timeline tracks how far a scroll container has been scrolled. At the top it is 0%, at the bottom it is 100%.
- A view progress timeline tracks an element's position as it passes through its scroll container's visible area, often called the scrollport. It starts when the element begins to enter and ends when it has fully left.
Nothing about the keyframes changes. A fade-in animation written for a time-based effect works unchanged on a scroll timeline. Only the clock driving it is different.
How do you build a scroll progress bar?
The classic example is a reading progress bar at the top of an article. It needs one element, one keyframe and two lines of animation setup:
@keyframes grow {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
.progress {
position: fixed;
inset: 0 0 auto 0;
height: 4px;
background: currentColor;
transform-origin: 0 50%;
animation: grow auto linear;
animation-timeline: scroll(root block);
}
scroll() creates an anonymous scroll timeline. It takes two optional arguments in any order:
- The scroller:
nearest(the default, the closest ancestor scroll container),root(the document's scroller) orself(the element itself). - The axis:
block(the default),inline,xory.
So scroll() on its own means "the nearest scroll container, on the block axis", and scroll(root block) pins it to the page scroll. Use linear easing here. Any other easing makes the bar feel like it lags behind your finger.
Animating transform rather than width matters. Transforms and opacity can be composited, so the browser can update them without layout, and the animation stays smooth even when the main thread is busy.
How do you animate an element as it enters the viewport?
For reveal effects, use view() instead. It creates a view progress timeline for the element the animation is applied to:
@keyframes reveal {
from { opacity: 0; translate: 0 2rem; }
to { opacity: 1; translate: 0 0; }
}
.card {
animation: reveal auto linear both;
animation-timeline: view();
animation-range: entry 0% cover 40%;
}
view() accepts an optional axis and an optional inset, for example view(block 100px auto), which shrinks the effective viewport so the timeline starts and ends earlier or later.
By default a view timeline covers the full journey, from the first pixel entering to the last pixel leaving. That is rarely what you want for a reveal, which is what animation-range is for. It sets where the animation starts and ends on the timeline, using named ranges:
| Range | What it covers |
|---|---|
cover | From the element starting to enter until it has fully left. The full timeline. |
contain | While the element is fully inside the scrollport, or fully covers it if it is taller. |
entry | While the element is crossing into the scrollport from the starting edge. |
exit | While the element is crossing out at the far edge. |
Each name can take a percentage. entry 0% cover 40% means the card is fully revealed by the time it is 40% of the way through its journey. A bare animation-range: entry means the animation plays from 0% to 100% of the entry phase only.
Add both to the fill mode. Without it, the element snaps back to its unanimated state whenever scroll progress is outside the range, which looks like flicker.
Why does animation-timeline get ignored?
This is the one to remember. The animation shorthand resets animation-timeline to auto, even though you can't set a timeline through the shorthand itself. So this does nothing:
.card {
animation-timeline: view();
animation: reveal auto linear both; /* resets the timeline */
}
Declare animation-timeline after the shorthand, as in the earlier examples, or give it higher specificity. The same thing happens if a later rule in another stylesheet uses the animation shorthand on the same element.
How do you link a scroller to an element outside it?
Anonymous timelines only look up the tree. If the element you want to animate is not a descendant of the scroller, for example a sticky header reacting to a sidebar's scroll, give the timeline a name:
.sidebar {
overflow-y: auto;
scroll-timeline: --sidebar block;
}
.header-shadow {
animation: shadow auto linear both;
animation-timeline: --sidebar;
}
.layout {
timeline-scope: --sidebar;
}
scroll-timeline names the scroller's timeline, and view-timeline does the same for view timelines. Named timelines are only visible to descendants by default. timeline-scope on a common ancestor lifts the name up so siblings and cousins can use it. Support for timeline-scope is newer than the core feature, so test it in each browser you care about.
How do you ship this safely?
Two guards cover most cases. First, feature-detect, so older browsers get the final state instead of invisible content:
@supports (animation-timeline: view()) {
.card {
animation: reveal auto linear both;
animation-timeline: view();
animation-range: entry 0% cover 40%;
}
}
Second, respect reduced motion. Scroll-linked movement can be uncomfortable for some people, and opacity-only reveals are a gentler fallback:
@media (prefers-reduced-motion: reduce) {
.card { animation: none; }
}
If you need the same timelines from script, the Web Animations API exposes ScrollTimeline and ViewTimeline objects you can pass as the timeline option to element.animate(). Check for them with 'ScrollTimeline' in window before using them. For most effects, though, the CSS version is shorter and easier to maintain.
Scroll-driven animations pair well with other CSS-first motion features. If you are animating between pages rather than within one, cross-document view transitions cover that side.
Key takeaways
- Scroll-driven animations replace time with scroll progress as the clock for normal
@keyframes. - Use
scroll()for progress through a scroll container andview()for an element moving through the viewport. animation-rangewithentry,exit,containandcovercontrols where on the timeline the effect plays.- Always declare
animation-timelineafter theanimationshorthand, or it gets reset. - Wrap effects in
@supportsand honorprefers-reduced-motion.
FAQ
Do CSS scroll-driven animations need JavaScript?
No. Everything here is plain CSS. A JavaScript API exists for the same timelines, but you only need it for effects built in script.
Are scroll-driven animations better for performance than scroll listeners?
They usually are. The browser knows the full relationship between scroll and animation up front, so animations of transform and opacity can run on the compositor instead of waiting on a main-thread event handler.
Which browsers support scroll-driven animations?
Current versions of Chrome, Edge, Safari and Firefox all support them, which made the core feature Baseline in October 2026. Some newer parts, like timeline-scope, have less consistent support, so test those.