Scroll animation: CSS, IntersectionObserver or a library
By Pulse Labs · Published · Updated · 3 min read
There are three ways to animate things as a page scrolls. Use CSS scroll-driven animations where you can: they need no JavaScript and the browser runs them. Use an IntersectionObserver when you need something that works in every current browser. Use a library when you need precise sequencing across many elements. Avoid reading scroll position on every scroll event; it is the slowest of the four.
Below, each approach has working code, then a measurement we took of the two JavaScript approaches on the same page. All code ran in Chrome 158 on an Apple M1 Pro on 22 November 2026.
The choice at a glance
| Approach | Works in | Main-thread cost | Best for |
|---|---|---|---|
| CSS scroll-driven animation | Current Chrome, Edge, Safari 26; Firefox per Chrome's table. See the CSS guide | Lowest. The browser runs it | Progress bars, reveals, small parallax, as an enhancement |
IntersectionObserver | Baseline widely available, in browsers since March 2019, per MDN | Low. The browser reports when elements enter or leave | Reveal once as an element arrives |
| A library (AOS, GSAP ScrollTrigger, Motion) | As documented by each | Varies. Depends on what you write | Choreography, pinned sections, tight timing |
| A scroll event listener | Everywhere | Highest. Runs on every scroll event | Almost nothing, today |
Reveal on scroll with IntersectionObserver
This reveals each card once as it enters, then stops watching it. The class that hides the cards is added by the script, and only when the visitor has not asked for reduced motion, so a failure leaves the cards visible. One more guard matters. An observer only reports a change, so if someone jumps to the end of the page with a link or the End key, the cards they skipped never intersect and never report. The pending set fixes that: each time any card reports, the callback also reveals pending cards that are already above the viewport. We found this by testing a jump, and our first version failed it.
<h1>This week</h1>
<div class="grid">
<article class="c"><h2>Mon</h2><p>Bread</p></article>
<article class="c"><h2>Tue</h2><p>Rolls</p></article>
<article class="c"><h2>Wed</h2><p>Rye</p></article>
<article class="c"><h2>Thu</h2><p>Focaccia</p></article>
<article class="c"><h2>Fri</h2><p>Baguette</p></article>
<article class="c"><h2>Sat</h2><p>Knots</p></article>
</div>.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 60px 0 200px; }
.c { padding: 18px; border: 1px solid #3a3160; border-radius: 12px; background: #1b1530; }
.c h2 { margin: 0 0 4px; font-size: 16px; } .c p { margin: 0; color: #cfc8ee; }
.reveal .c { opacity: 0; transform: translateY(24px); transition: opacity .5s ease-out, transform .5s ease-out; transition-delay: calc(var(--i, 0) * 70ms); }
.reveal .c.in { opacity: 1; transform: none; }if (!matchMedia("(prefers-reduced-motion: reduce)").matches && "IntersectionObserver" in window) {
document.body.classList.add("reveal");
const cards = [...document.querySelectorAll(".c")];
cards.forEach((c, i) => c.style.setProperty("--i", i % 3));
const pending = new Set(cards);
const show = (c) => { c.classList.add("in"); pending.delete(c); io.unobserve(c); };
const io = new IntersectionObserver((entries) => {
for (const e of entries) if (e.isIntersecting) show(e.target);
pending.forEach((c) => { if (c.getBoundingClientRect().bottom < 0) show(c); });
}, { threshold: 0.2 });
cards.forEach((c) => io.observe(c));
}What it costs: a measurement
We built one page with 400 blocks, each 120 px tall, and scrolled it top to bottom in steps of 40 px, one step per frame, in Chrome 158 driven by Playwright on an Apple M1 Pro. One version used a scroll listener that calls getBoundingClientRect() on every block each time; the other used an IntersectionObserver with the same reveal. We summed the time spent inside each callback with performance.now(). Each version ran five times.
| Version | Callbacks per run | Time inside callbacks, range over 5 runs | Median |
|---|---|---|---|
Scroll listener with getBoundingClientRect() | 1,380 | 594 to 732 ms | about 635 ms |
IntersectionObserver | 395 | 5.6 to 7.1 ms | about 6.6 ms |
When to reach for a library
If you need sections that pin while content moves, or a sequence timed to the pixel, write it with a library. AOS is the lightest to adopt, driven by data-aos attributes after one AOS.init() call. GSAP says it is free for all users as of our check, and its ScrollTrigger is part of the library's scroll tools. Motion says its core library is free and open source on its site. The tool comparison lines these up against each other.
When you do not want to write any of it
A site that already exists has dozens of sections and cards. Writing and maintaining reveals for all of them is real work. MotionLift is a single script that finds the sections, cards, headings and pictures on your page and animates them as visitors scroll, in the page's own colours, and respects reduced motion. It is not a library to code against, so if you want to control each movement, use one of the approaches above.