CSS Scroll Animations Without JavaScript: The animation-timeline Guide
September 29, 2026 | 10 min read | CSS
By Syed · Frontend Engineer & Creator of UITweak
For years, animating elements on scroll meant reaching for JavaScript: scroll listeners, IntersectionObserver, or a library. CSS now has a native answer: scroll-driven animations. With animation-timeline, an animation's progress is driven by scrolling instead of time, which means progress bars, reveal effects, and parallax that run entirely in the browser's compositor. No JavaScript, no jank from scroll handlers.
Shortcut: design the keyframes visually in our free CSS Animation Generator, then attach them to a scroll timeline using the technique below.
1. How Scroll-Driven Animations Work
A normal CSS animation is driven by a clock: it plays from 0% to 100% over a duration. A scroll-driven animation replaces the clock with a timeline tied to scrolling. As the user scrolls, the animation scrubs forward and backward through its keyframes. Scroll back up, and the animation reverses. There are two timelines:
scroll(): tracks the scroll position of a scroll container (usually the whole page). Best for page-level effects like progress bars.view(): tracks a single element's visibility as it moves through the viewport. Best for reveal-on-scroll effects.
The mental model is simple: animation-timeline answers what drives the animation, while animation-range answers when it starts and ends.
2. Recipe: Reading Progress Bar with scroll()
The classic use case. A bar at the top of the page fills as you scroll through an article, in about ten lines of CSS:
@keyframes fill-bar {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
.progress-bar {
position: fixed;
top: 0; left: 0; right: 0;
height: 4px;
background: #4f46e5;
transform-origin: left;
animation: fill-bar linear both;
animation-timeline: scroll();
}Note the linear timing function: easing functions distort the mapping between scroll position and progress, so scroll-driven animations almost always use linear. The both fill mode keeps the bar at 0% before scrolling starts and 100% at the end.
3. Recipe: Reveal on Scroll with view()
This replaces the most common IntersectionObserver pattern: elements fading and sliding in as they enter the viewport.
@keyframes reveal {
from { opacity: 0; transform: translateY(24px); }
to { opacity: 1; transform: translateY(0); }
}
.reveal {
animation: reveal linear both;
animation-timeline: view();
/* play the animation while the element travels
from entering the viewport to 60% covered */
animation-range: entry 0% cover 60%;
}animation-range is the fine-tuning knob. entry 0%means "when the element first touches the viewport" and cover 60%means "when 60% of the scroll distance covering the element has passed". Without a range, the animation maps to the element's entire journey through the viewport, which often feels too slow.
4. Recipe: Parallax Hero
Move a background slower than the foreground for depth. Because the animation is scroll-driven, it stays perfectly in sync with scrolling, something JavaScript parallax often gets slightly wrong:
@keyframes parallax {
from { transform: translateY(-10%); }
to { transform: translateY(10%); }
}
.hero-bg {
animation: parallax linear both;
animation-timeline: scroll();
animation-range: 0 600px;
}Here animation-range: 0 600px ties the animation to the first 600 pixels of page scroll, so the parallax only happens while the hero is on screen. Keep the movement subtle: large parallax shifts cause motion sickness for some users.
5. Browser Support and Fallbacks
Scroll-driven animations work in Chromium browsers and recent Safari and Firefox versions, but older browsers ignore animation-timelineentirely. The safe pattern is progressive enhancement: the element's final state must be its natural, un-animated state.
- In the reveal recipe above, the
tokeyframe equals the element's normal style (opacity 1, no transform). If the browser ignores the animation, the element simply appears. Nothing breaks. - Never hide elements with CSS and reveal them only via animation. That leaves content invisible where timelines are unsupported.
- Gate with
@supports (animation-timeline: view())when you need different styling for supporting browsers. - For a JavaScript fallback, a tiny IntersectionObserver that adds a class is enough. Keep it as an enhancement, not a requirement.
6. Performance Notes
- Scroll-driven animations run on the compositor thread, which is why they stay smooth where scroll listeners jank. Animate
transformandopacityonly. - Avoid animating properties like
width,top, orfilteron scroll: they force layout or paint every frame and erase the performance advantage. - Respect
prefers-reduced-motion: disable scroll-linked movement for users who ask for it, since parallax and reveals are exactly the kind of motion that causes discomfort.
@media (prefers-reduced-motion: reduce) {
.reveal, .hero-bg, .progress-bar {
animation: none;
}
}Design the keyframes, skip the JS
Build your reveal, parallax, or progress keyframes on a live preview in the Animation Generator, then attach them to a scroll timeline with the recipes above.
Open the Animation Generator, it's freeNamed Scroll Timelines: Animating Inside a Scroller
scroll() with no arguments tracks the nearest scrollable ancestor, which is usually the page. For a horizontal carousel with its own progress indicator, name the timeline instead. scroll-timeline-name goes on the scroller, scroll-timeline-axis: inline marks it horizontal, and the indicator's animation-timeline references that name. Keep the animated element inside the element that declares the name: named timelines resolve through the ancestor chain, so an indicator sitting outside the scroller will not find it. This is the piece that turns scroll-driven animation from page-level effects into component-level effects. I reach for it whenever the scrolling region is a component rather than the document.
.carousel {
overflow-x: auto;
scroll-timeline-name: --carousel;
scroll-timeline-axis: inline;
}
.carousel-progress {
animation: fill linear both;
animation-timeline: --carousel;
}
@keyframes fill {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}Named View Timelines: One Subject, Many Animations
view() is anonymous: it measures the animated element itself. view-timeline-name lets you measure a different element instead. Name the timeline on a section, and any descendant can animate against that section's journey through the viewport. The classic uses: a sticky chapter header whose progress bar fills as the chapter scrolls past, or navigation dots that light up per section. Same scoping rule as scroll timelines: the animated elements must be descendants of the element that names the timeline. One named subject can drive a whole choreography of descendants, each with its own range.
.chapter {
view-timeline-name: --chapter;
}
.chapter-progress {
position: sticky;
top: 0;
animation: fill linear both;
animation-timeline: --chapter;
animation-range: entry 0% exit 100%;
}animation-range Keywords, Precisely
Four keywords define the measurement window. entry covers the subject arriving at the viewport edge. exit covers it leaving. cover spans the whole journey from first touch to fully past. contain covers only the stretch where the subject sits fully inside the viewport. Percentages are progress along that window, not viewport fractions: entry 0% is the moment of first touch, cover 50% is halfway through the journey. The mistake I see most often is leaving the default full-journey range on a tall section, which makes the animation crawl across thousands of pixels of scrolling. Tighten the range to the part of the journey that matters and the motion snaps into focus.
The JavaScript Bridge: ScrollTimeline
Some effects genuinely need JavaScript: a canvas visualization synced to scroll, a numeric readout, a WebGL scene. Falling back to scroll listeners throws away the compositor advantage, so Chromium offers the Web Animations API equivalent: element.animate() with a ScrollTimeline instead of a duration. The animation runs on the same scroll-linked clock as the CSS version. It is Chromium-only for now, so feature-check with "ScrollTimeline" in window and keep an IntersectionObserver fallback for everyone else. I use this sparingly. Most scroll effects belong in CSS, and the bridge exists for the ones that cannot live there.
if ("ScrollTimeline" in window) {
dial.animate(
[{ transform: "rotate(0turn)" }, { transform: "rotate(1turn)" }],
{
timeline: new ScrollTimeline({
source: document.documentElement,
axis: "block",
}),
fill: "both",
}
);
}Debugging: The Timeline Is Not Moving
When nothing animates, check these in order. First, the element is not actually scrolling: scroll() binds to the nearest scrollable ancestor, and if that ancestor never scrolls, progress sits at zero forever. Second, the fill mode is missing: without a fill, the pre-scroll state flashes or the end state snaps back. Third, the easing is not linear: any easing curve remaps scroll position to progress, which reads as the animation lagging behind the scroll. Fourth, content-visibility: auto on the subject can interfere with view() measurement; test with it off. Nine times out of ten it is the first one. The wrong scroller is the bug.
scroll(root), scroll(nearest), scroll(self): Picking the Scroller
scroll() with no arguments is shorthand for scroll(nearest): the nearest scrollable ancestor. Inside a modal with its own scrollable region, that is the modal, not the page, which surprises people building page-level progress bars inside scrollable layouts. scroll(root) pins the timeline to the document scroller explicitly. scroll(self) measures the element's own scrolling, useful when the animated element is itself the scroller. I write the keyword explicitly every time. It costs a few characters and removes the "which scroller?" question from every debugging session.
/* page-level progress: the document scroller, even inside nested scroll regions */
.progress-bar {
animation: fill linear both;
animation-timeline: scroll(root);
}
/* driven by the element's own scrolling */
.list {
overflow-y: auto;
animation-timeline: scroll(self);
}Keep reading: