Scroll Triggered Animations: CSS vs JavaScript Explained
Key takeaways
- CSS scroll-driven animations use animation-timeline with scroll() or view() timelines, replacing animation-duration with scroll progress as the clock.
- Pure CSS scroll triggered animations add zero JavaScript and run off the main thread, but Firefox and Safari support still lags Chrome.
- Use GSAP ScrollTrigger when you need pinning, scrubbed easing, or callbacks; use CSS when the effect is a simple visual driven by scroll position.
- Animate only transform and opacity, wrap effects in prefers-reduced-motion, and keep content readable in the DOM without the animation playing.
- Unsupported browsers should get a clean static fallback via @supports or progressive enhancement, never a broken or hidden page.
Scroll triggered animations are effects that run as the page scrolls, driven either by pure CSS (the animation-timeline property) or by a JavaScript library watching scroll position. This article shows the same animation built both ways, side by side, plus the fallback for unsupported browsers, so you can pick the right approach for client sites.
What are scroll triggered animations and how do they work?
Scroll triggered animations move, fade, or pin elements based on where the reader is on the page. The browser watches the scroll position and drives the animation from it, so the effect follows your thumb or mouse wheel exactly, forward and backward.
Scroll progress as the animation clock
Traditional animations run on time: a keyframe plays over 0.5 seconds whether you scroll or not. Scroll-driven animations swap time for progress. As MDN's scroll-driven animations documentation explains, a scroll container's progress becomes the animation's timeline, so 40% down the page means 40% through the animation. We cover one common pattern, pinning, in our sticky scroll animation guide.
Where the trigger lives: viewport vs scroll position
There are two clocks to choose from. Scroll progress tracks the whole page: reach 50% of the document, fire the effect. View progress tracks an element against the viewport: when a card crosses the bottom edge, start it; when it exits the top, end it. The first suits page-length storytelling, the second suits per-section reveals.
How do CSS scroll-driven animations and animation-timeline work?
CSS scroll-driven animations tie an animation's progress to scroll position instead of time. Instead of animation-duration, you set animation-timeline to a scroll-based timeline, and the browser advances the animation as the user scrolls. No JavaScript, no scroll listeners, no main-thread work.
scroll and view: the two timelines
The scroll() function creates a scroll progress timeline: it tracks how far an element's scroll container has been scrolled, from 0% to 100%. The view() function creates a view progress timeline: it tracks an element's position as it moves through the viewport, which is what drives reveal-on-scroll effects. Both plug straight into animation-timeline.
animation-range and why it replaces scroll math
animation-range defines where the timeline starts and stops, in plain values like animation-range: entry 0% entry 100% or cover 20% 80%. That replaces the hand-rolled JavaScript you'd otherwise write: measuring offsets, subtracting viewport heights, recalculating on resize. The browser does the math natively, so the animation stays accurate across breakpoints without a resize handler.
The catch: you still write the keyframes and wire the timeline per element. Our guides show how a visual builder can handle that wiring for you, with the same CSS output underneath.
Scroll triggered animations in CSS vs JavaScript: which should you use?
Use CSS scroll-driven animations when the animation is purely visual and driven by scroll position. Use JavaScript (GSAP's ScrollTrigger, for example) when you need scrubbed timelines with easing, pinned scenes, or animations that respond to more than scroll.
What JS libraries give you that CSS cannot
JavaScript gives you pinning, scrubbing with custom easing, and callbacks at scroll thresholds. The hand-coded GSAP / ScrollTrigger stack is the status quo for Apple-style scroll pages, and nothing in CSS replicates a pinned scene yet. You also get broader browser coverage today: caniuse.com shows scroll-driven animations unsupported in Firefox and Safari, so CSS-only means shipping fallbacks.
What CSS gives you that JS cannot
CSS runs off the main thread, so it stays smooth even when JavaScript is busy, and it needs no library download. For WordPress builders, that matters: a fade or translate on entry costs you a few lines instead of a dependency.
CSS animation-timeline | GSAP / ScrollTrigger | No-code (Midground) | |
|---|---|---|---|
| Pinning | No | Yes | Yes |
| Runs off main thread | Yes | No | Mixed |
| Library payload | None | Yes | Theme handles it |
| Works in Firefox/Safari today | No | Yes | Via fallbacks |
Honest limitation: Midground can't do arbitrary JS timelines either; it covers pinned scenes, parallax and 3D, not every easing curve you could hand-write. We compare the approaches in more depth at https://midgroundwp.com/apple-style-scroll-wordpress/.
The same animation, twice: CSS vs JavaScript code compared
Here is a fade-and-rise reveal, written both ways, so you can see exactly what each approach costs you in markup and moving parts.
Version 1: pure CSS with animation-timeline
@keyframes reveal {
from { opacity: 0; transform: translateY(40px); }
to { opacity: 1; transform: translateY(0); }
}
.reveal {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% cover 30%;
}
No JavaScript file, no event listeners, no scroll handler. The browser drives the animation off the element's own position in the viewport, and it runs on the compositor so it stays smooth even while the main thread is busy.
Version 2: the same effect with a JS scroll library
gsap.from(".reveal", {
opacity: 0,
y: 40,
scrollTrigger: {
trigger: ".reveal",
start: "top 90%",
end: "top 60%",
scrub: true
}
});
Same visual result, but now you are shipping a library, wiring triggers to selectors, and trusting the main thread to keep up. The long paragraph worth pinning: the CSS version is eight lines and zero dependencies, while the JS version needs a 60kb-plus file, a trigger config per element, and a mental model where the animation lives in JavaScript and the HTML is just a hook. On a client site built on GeneratePress or Kadence, that difference decides whether your scroll triggered animations are a feature of the page or a layer bolted on top of it. This is the trade-off Midground's builder automates: it outputs CSS-driven motion where the browser supports it, and you can inspect exactly what ships on https://midgroundwp.com/features/.
The @supports fallback: what unsupported browsers see
@supports not (animation-timeline: view()) {
.reveal { opacity: 1; transform: none; }
}
Unsupported browsers simply show the finished state. No flash of hidden content, no polyfill, no extra request.
What happens in browsers that don't support scroll-driven CSS animations?
Nothing dramatic. A browser without animation-timeline support skips the animation entirely and shows the element in its final or default state, depending on how you wrote the keyframes. The page still scrolls and still works. Firefox and Safari shipped support later than Chrome, so for a while a meaningful share of your client traffic saw static pages.
Progressive enhancement vs feature detection
Progressive enhancement means the animation is decoration, not function: content readable, links clickable, no JS required. Feature detection means you check support first, then serve a JavaScript fallback only where needed. For client work, progressive enhancement is the safer default because it fails silently and costs you nothing to maintain.
The three fallback strategies, ranked
- Do nothing. Static content is a perfectly acceptable fallback for fades and parallax.
- CSS
@supportsswap. Serve a simpler keyframe animation to unsupported browsers, no JavaScript involved. - JavaScript library. GSAP or ScrollTrigger covers every browser, at the cost of shipping and maintaining a script.
If you'd rather not write any of this yourself, a no-code tool that handles fallbacks for you is the point. Midground (https://midgroundwp.com/) treats scroll motion as progressive enhancement, so unsupported browsers get a clean static page instead of a broken one.
How do you add scroll triggered animations without hurting performance?
The rule that matters most: animate only transform and opacity. Both run on the compositor thread, so the browser can update them every frame without recalculating layout or repainting. Animating top, width, or box-shadow forces layout work on the main thread, and that shows up immediately in frame rates on mid-range phones.
Animate only transform and opacity
Stick to translate, scale, rotate, and opacity changes. If an effect seems to need a layout property, it can usually be rebuilt with a transform instead. This is the same constraint the W3C CSS Scroll-Driven Animations specification is built around: the browser drives the animation from scroll position, with no main-thread work per frame.
Why scroll listeners are the slow path
A JavaScript scroll event fires irregularly and runs on the main thread, competing with hydration, image decoding, and everything else your theme loads. The hand-coded GSAP / ScrollTrigger stack handles this well with its own ticker, but a naive addEventListener('scroll', ...) plus style writes is the slow path. CSS animation-timeline avoids the problem entirely because the browser runs the animation off the main thread, which is the approach Midground generates: no listeners, no per-frame JavaScript, just declarative keyframes the compositor can schedule itself.
What are the best scroll triggered animation examples on real websites?
The strongest scroll triggered animation examples share two traits: the motion carries meaning, and the page stays fast enough that the motion actually gets seen.
Pinned product scenes
Apple's product pages are the reference point here: a section pins, the product stays fixed in view, and scrolling scrubs through features one at a time. You get the same effect with GSAP's ScrollTrigger pinning, or with CSS position: sticky plus an animation-timeline: scroll() driven sequence. The pattern works because the reader controls the pace, so nothing is missed and nothing annoys.
Text reveals and horizontal galleries
The second family is simpler: headlines that reveal word by word, and galleries that scroll sideways as you scroll down. Both translate vertical scroll into horizontal or staggered movement, which is one line of scroll() timing in CSS or a few ScrollTrigger lines in JavaScript. Used sparingly, they make a landing page feel finished rather than decorated.
When should you avoid scroll triggered animations altogether?
Skip them when the page's job is reading, not showing. Long-form articles, documentation, pricing pages and checkout flows convert on clarity; motion competes with the text and slows the build for no gain.
Accessibility: prefers-reduced-motion
Respect the media query. Wrap every animation in @media (prefers-reduced-motion: no-preference) so users who opt out get a static page. Google's web.dev guide to scroll-driven animations treats this as a baseline, not an extra.
Content that must be readable without scrolling tricks
Anything pinned, faded or scrubbed must still make sense as plain text in the DOM. If a message only lands when the animation plays, it will fail for screen readers, search crawlers and anyone on a slow connection.
How do you build scroll triggered animations in WordPress without code?
What your current stack can and cannot do
Astra, Kadence, GeneratePress, and Elementor each support basic entrance effects like fade-ins, but none offer pinned scenes or real 3D through their native controls. Elementor's motion effects cover parallax and scrolling triggers; anything more means hand-writing GSAP and ScrollTrigger and maintaining it yourself. GenerateBlocks and Greenshift are leaner, with Greenshift shipping animation controls closer to what you want.
Choosing between CSS, a JS stack, and a purpose-built tool
Use pure CSS with animation-timeline when the effect is simple and your theme lets you add it. Use a GSAP stack when you need precise, complex choreography and can maintain the code. Use a purpose-built tool like Midground when you want Apple-style scroll pages across client sites without writing or maintaining that JavaScript. Honestly: Midground is a theme and builder, so you are choosing its layout system too, and it costs more than free defaults. If your needs are a fade-in per section, your current stack already does it. If you are rebuilding Elementor pages by hand to escape their bugs, a dedicated scroll tool earns its place.
FAQ
Do scroll triggered animations work on mobile browsers?
Yes, but with a split. Chrome-based mobile browsers support CSS animation-timeline natively, while Firefox and Safari lag behind, so a share of mobile visitors see the fallback state. The effects themselves are touch-friendly because scroll position drives the timeline, so swiping scrubs the animation just like a mouse wheel does.
Are scroll triggered animations bad for SEO or Core Web Vitals?
Not if you follow two rules: animate only transform and opacity, and keep content readable in the DOM without the animation playing. CSS-driven effects run off the main thread, so they cost little. JavaScript scroll listeners on the main thread are where frame rates and INP start to suffer on mid-range phones.
Can I add scroll triggered animations to Elementor or GeneratePress without a plugin?
Only basic ones. Elementor's native motion effects cover parallax and scrolling triggers, and GeneratePress handles simple fade-ins through custom CSS, but neither offers pinned scenes or real 3D without hand-writing GSAP and ScrollTrigger. For Apple-style pinned sequences, you need a dedicated tool or your own JavaScript.
How much JavaScript do scroll triggered animations add to my page?
A pure CSS approach adds zero: no library, no listeners, no per-frame work. A GSAP stack adds a file of roughly 60kb or more plus a trigger configuration per element, and it runs on the main thread. A no-code builder varies, but Midground outputs declarative CSS where the browser supports it.
What is the difference between parallax and scroll triggered animations?
Parallax is one specific effect: background layers move at a different speed than the foreground, creating depth. Scroll triggered animations is the broader category, covering parallax plus reveals, pinned scenes, scrubbed timelines, and horizontal galleries. Every parallax effect is scroll-driven, but most scroll-driven animations are not parallax.
