Tutorials
CSS scroll-driven animations: progress bars, reveals and parallax without JavaScript
Learn CSS scroll driven animations: animation-timeline with scroll() and view(), animation-range, named timelines, a live demo, fallbacks and reduced motion.
CSS scroll-driven animations link an animation's progress to scrolling instead of to time. Scroll halfway down and the animation is halfway through. Scroll back up and it plays in reverse. You write ordinary @keyframes, then swap the clock for a scroll timeline with one property: animation-timeline.
This used to need a scroll listener or a library. Now a reading progress bar, a fade-in as cards enter the viewport, or a gentle parallax can be pure CSS. This guide covers the two timeline functions, animation-range, named timelines, feature detection, and when to reach for IntersectionObserver or GSAP ScrollTrigger instead.
Scroll inside this box
End of the article
How the animation is put together
There is no duration and no delay in the usual sense. The timeline replaces both, and animation-range decides which stretch of the scroll the keyframes fill.
| Part | Property | Duration | Delay | Easing |
|---|---|---|---|---|
| Progress bar | transform: scaleX(0 → 1) | Full scroll of the box, scroll(nearest block) | None, starts at scroll top | linear |
| Each card | opacity 0 → 1, translateY(32px) scale(.96) → none | From entry 10% to cover 35% of its own view() | Starts when the card is 10% into the box | cubic-bezier(.2, .8, .2, 1) |
| Cards, reduced motion | opacity 0 → 1 only | Same range | Same | Same |
scroll(): progress through a scroll container
scroll() creates an anonymous timeline from a scroll container. 0% is the top of the scroll range, 100% is the bottom. It takes two optional arguments: which scroller and which axis.
/* a reading progress bar for the whole page */
.progress {
position: fixed; inset: 0 0 auto 0; height: 4px;
background: #fb9f3d; transform-origin: 0 50%;
animation: grow linear both;
animation-timeline: scroll(root block);
}
@keyframes grow {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
The scroller can be nearest (the default, the closest ancestor that scrolls), root (the document) or self. The axis can be block (the default), inline, x or y. The page bar above needs root because a fixed element's nearest scrolling ancestor is not necessarily the document. The demo uses nearest, because the bar sits inside the scrolling box.
animation shorthand resets animation-timeline to auto. Always write animation-timeline after the shorthand, or the element falls back to a time-based animation with no duration and appears not to move.Notice that the shorthand has no duration. With a scroll timeline the duration is worked out from the scroll range. Some older articles add animation-duration: 1ms for an early Firefox implementation; it does no harm in Chromium.
view(): progress through an element's visibility
view() creates a timeline from the element's own position inside its scroller. The timeline starts when the element's leading edge first appears at the end of the scrollport and finishes when its trailing edge leaves at the start. That is ideal for reveal-on-scroll, because every element gets its own timeline with no extra code.
.reveal {
animation: reveal cubic-bezier(.2, .8, .2, 1) both;
animation-timeline: view();
animation-range: entry 10% cover 35%;
}
@keyframes reveal {
from { opacity: 0; transform: translateY(32px); }
to { opacity: 1; transform: none; }
}
view() also accepts an axis and an inset, such as view(block 80px 0), which shrinks the area that counts as visible. That is handy when a sticky header covers the top of the viewport.
animation-range: choosing the window
Without a range, a view() animation runs across the whole time the element is anywhere on screen, so a reveal would only finish as the element leaves. animation-range trims it. Each end is a named range plus a percentage:
entry: the element is crossing into the scrollport.exit: the element is crossing out.contain: the element is fully inside (or, if it is taller than the scrollport, fully covering it).cover: the full journey, from first pixel in to last pixel out.entry-crossingandexit-crossing: like entry and exit, measured against the element's size.
entry 0% entry 100% means "play while the element slides in, finish once it is fully visible". exit 0% exit 100% is the mirror, useful for fading things out as they leave. You can also use lengths on scroll() timelines, for example animation-range: 0 400px to finish a header shrink after the first 400 px of scroll.
Named timelines
Anonymous timelines only work when the animated element is the subject (for view()) or a descendant of the scroller (for scroll()). To animate one element based on another, name the timeline.
.gallery {
overflow-x: auto;
scroll-timeline: --gallery inline;
}
.gallery-dots .active {
animation: slide-dot linear both;
animation-timeline: --gallery;
}
.hero-image {
view-timeline: --hero block;
}
.hero-caption {
animation: fade-out linear both;
animation-timeline: --hero;
animation-range: exit 0% exit 60%;
}
Timeline names must start with two dashes. A named timeline is visible to the element that declares it and its descendants. If the animated element lives elsewhere in the tree, declare timeline-scope: --gallery on a shared ancestor to lift the name up to it.
Parallax image
A slow parallax is a view() animation on an image inside a clipped frame.
.parallax { overflow: hidden; height: 360px; }
.parallax img {
height: 130%; width: 100%; object-fit: cover;
animation: drift linear both;
animation-timeline: view();
animation-range: cover 0% cover 100%;
}
@keyframes drift {
from { transform: translateY(-15%); }
to { transform: translateY(0); }
}
Keep the travel small. Fifteen percent of the frame is noticeable without being disorientating. Use linear here: any other curve makes the image speed up and slow down against the scroll, which feels wrong. The guide to the linear() function explains when a multi-stop linear curve is worth it instead.
Feature detection and fallbacks
Support is good in Chromium browsers and arriving elsewhere: Safari has added it in recent releases and Firefox has had it behind a flag. Check caniuse for the current picture. Wrap the scroll-driven rules in @supports so browsers without it never get stuck on a from keyframe.
.reveal { opacity: 1; }
@supports (animation-timeline: view()) {
.reveal {
animation: reveal cubic-bezier(.2, .8, .2, 1) both;
animation-timeline: view();
animation-range: entry 10% cover 35%;
}
}
This is the important part: outside the @supports block the element is simply visible. A reveal is an enhancement. If you want the effect everywhere, the fallback is a small script: an IntersectionObserver that adds a class for reveals, or a passive scroll listener for a progress bar, as in the demo above. In JavaScript, CSS.supports('animation-timeline: view()') tells you which path to take.
Compared with IntersectionObserver and GSAP ScrollTrigger
| CSS scroll timelines | IntersectionObserver | GSAP ScrollTrigger | |
|---|---|---|---|
| Progress follows scroll | Yes, frame by frame | No, fires at thresholds | Yes, with scrub |
| JavaScript needed | None | A few lines | Library plus setup |
| Main thread | Transform and opacity can run off it in Chromium | Callbacks on main thread; the animation itself can be CSS | Updates on main thread |
| Pinning, snapping, callbacks | Pin with position: sticky; no callbacks | Callbacks only | Built in |
| Browser support | Growing; needs a fallback | All modern browsers | All modern browsers |
Use CSS for progress bars, reveals, simple parallax and header shrinks. Use IntersectionObserver when you want a time-based animation that plays once when something appears, which is often calmer than scroll-linked motion. Reach for ScrollTrigger for long pinned stories, sequenced timelines and smoothed scrubbing, or when you need identical behaviour in every browser today. The GSAP vs CSS animation comparison goes into the wider trade-offs.
Many reveals you see on existing sites are time-based: a CSS transition or a GSAP tween that starts when the element comes into view. If you want to match one, Capture Motion records its keyframes, durations and easing while it plays. You can paste those keyframes into your own @keyframes and attach them to view(), or keep them time-based behind an observer. The guide to copying an animation from any website walks through it.
Reduced motion
Scroll-linked movement is one of the main triggers for motion sickness, because the content moves at a different rate from the user's input. Under prefers-reduced-motion: reduce, turn off parallax entirely and reduce reveals to an opacity fade. A progress bar that only grows in width is usually fine to keep.
@media (prefers-reduced-motion: reduce) {
.parallax img { animation: none; transform: none; height: 100%; }
@keyframes reveal { from { opacity: 0; } to { opacity: 1; } }
}
Redefining the keyframes inside the media query keeps the timeline and range in one place. The prefers-reduced-motion guide covers testing and the JavaScript side.
Questions
Which browsers support CSS scroll-driven animations?
Chromium browsers (Chrome, Edge, Opera) support them, and Safari has added support in recent releases. Firefox has had an implementation behind a flag. Check caniuse before relying on them, and always ship a fallback.
Why does my scroll-driven animation not run?
The most common cause is setting animation-timeline before the animation shorthand. The shorthand resets animation-timeline to auto, so declare the timeline after it. Also check that the element actually has a scrolling ancestor.
Should I use linear easing for scroll-driven animations?
Usually yes. The scroll position already controls the pace, so linear makes the element follow the finger or wheel directly. A curve is fine for reveals where you want the motion to settle near the end of its range.
Can I copy a reveal-on-scroll effect from another site?
Many reveals are time-based CSS transitions or GSAP tweens started when the element comes into view. Capture Motion records their keyframes, durations and easing while they play, and you can then drive the same keyframes with view() in your own CSS.
