Scroll-linked motion has a bad reputation, and it earned it. The classic implementation is a scroll listener that reads element positions and writes styles, sixty-plus times a second, on the main thread, in a callback that fires more often than frames render.
// The old way. Don't.
window.addEventListener('scroll', () => {
const rect = el.getBoundingClientRect(); // forces layout
el.style.opacity = computeOpacity(rect); // invalidates it again
});
Every getBoundingClientRect() forces a synchronous layout. Doing it in a scroll handler means layout, style, layout, style: the pattern known as layout thrashing. On a phone it drops frames immediately, and scrolling is the one interaction where users notice every dropped frame.
CSS scroll-driven animations fix this at the source: the animation is declared, not computed, and runs on the compositor.
Two timelines
Instead of time, animations can be driven by a scroll position.
scroll(): progress through a scroll container. Zero at the top, one at the bottom. Good for anything tracking overall page progress:
.progress-bar {
transform-origin: left;
animation: grow linear;
animation-timeline: scroll();
}
@keyframes grow {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
A reading-progress bar, with no JavaScript, running off the main thread.
view(): progress of an element through the viewport. Zero as it enters, one as it leaves. This is the one you want most of the time:
.card {
animation: rise linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}
@keyframes rise {
from { opacity: 0; transform: translateY(24px); }
to { opacity: 1; transform: none; }
}
Every card animates as it scrolls into view. No observer, no listener, no classes toggled.
animation-range is where the control is
view() alone spans the element’s entire journey across the viewport, which is almost never what you want. An element would spend the whole screen fading in. animation-range narrows it to a phase:
entry: from first pixel visible to fully visibleexit: from starting to leave until fully gonecover: the whole journey, edge to edgecontain: while the element is entirely within the viewport
Reveal-on-scroll is entry 0% to entry 100%, and usually better as entry 20% to entry 80% so it finishes before the element is fully on screen rather than still animating while being read.
Use linear
Scroll-driven animations should almost always be animation-timing-function: linear. The scroll position is the easing. It comes from the user’s finger, which already has natural acceleration and deceleration. Applying an ease-out on top double-eases the motion and produces a distinctive sluggish, rubbery feel where the element lags the scroll.
This is one of the genuine exceptions to ease-out being the default. The rule assumes the browser controls the timeline. Here the user does.
The JavaScript version, done properly
Where CSS is not enough, because of support gaps or logic keyframes cannot express, the correct tool is IntersectionObserver, not a scroll listener:
const io = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
io.unobserve(entry.target); // one-shot: stop watching
}
}
},
{ rootMargin: '0px 0px -10% 0px' },
);
document.querySelectorAll('.reveal').forEach((el) => io.observe(el));
The observer fires only at threshold crossings, not on every scroll event, and reports geometry the browser already computed, so there is no forced layout. The unobserve matters: for a one-shot reveal, an observer left watching a hundred elements is work with no payoff.
For genuinely continuous scroll-linked values, the Web Animations API can also accept a ScrollTimeline directly, which keeps things off the main thread while letting JavaScript define the keyframes.
What is actually worth building
The technique being cheap does not make every use of it good.
Reveal-on-scroll is overused. Content that fades in as you reach it is now so common it reads as default rather than considered, and it has a real cost: text that is not yet opaque cannot be read, so a fast scroller sees a page of half-visible paragraphs. If you do it, keep it fast, keep the translate small (8–24px), and finish it early in the entry range.
Progress indicators are genuinely useful. A reading-progress bar answers a real question and costs three lines.
Parallax needs restraint. Small differential movement suggests depth. Large differential movement makes people ill, and it is one of the strongest vestibular triggers on the web.
Scroll-jacking remains bad. Nothing about these APIs changes the fact that overriding scroll velocity takes control from the user.
The good test: does the motion tell the user something about the content or their position in it? A progress bar does. A subtitle fading in does not.
Reduced motion is non-negotiable here
Scroll-driven animation is the highest-risk category for vestibular disorders: motion tied directly to scrolling, often across large distances, unavoidable while reading.
@media (prefers-reduced-motion: reduce) {
.card {
animation: none;
opacity: 1;
transform: none;
}
}
Reset both the animation and the properties it was interpolating. Removing the animation while leaving opacity: 0 in the base rule is a common bug that hides the content entirely, and it is exactly the users who most need the content who hit it.
Support
Scroll-driven animations shipped in Chromium first and support has been expanding; treat them as a progressive enhancement and check current support rather than trusting a date in a blog post. The graceful path is that unsupported browsers ignore animation-timeline and run the animation on a normal time-based timeline, so make sure the fallback is acceptable, or gate on @supports (animation-timeline: view()).
The safest pattern remains: content visible and readable by default, motion added on top. Then no browser, setting, or failure mode can hide anything.