CSS Scroll-Driven Parallax: Building 120 FPS Depth with animation-timeline: view()
Modern CSS enables native scroll-driven parallax with zero JavaScript using the View Timeline API: animation: parallaxPan linear; animation-timeline: view(); animation-range: entry 0% exit 100%;. By mapping individual depth planes to different translateY travel distances on the browser's compositor thread, you achieve silky 120 FPS depth motion that never blocks the main thread or causes scroll jank.
Step 1: The Architecture of view() Timelines
Unlike scroll() which tracks the entire document, view() tracks an element as it enters and leaves the visible scrollport. Define an animation and link it directly using animation-timeline: view().
/* Pure CSS View-Driven Parallax */
.parallax-layer-bg {
animation: parallaxBackdrop linear;
animation-timeline: view();
animation-range: entry 0% exit 100%;
}
@keyframes parallaxBackdrop {
from { transform: translateY(-15%); }
to { transform: translateY(15%); }
}
Step 2: Calibrating Multi-Plane Depth Speeds
Convincing physical depth relies on differential velocity: background stars/mountains move at 0.1x to 0.3x scroll speed, midground graphics move at 0.5x, and foreground cards glide at 1.0x.
/* Slow Background: 40px travel */
.depth-back {
animation: panSlow linear;
animation-timeline: view();
}
@keyframes panSlow {
from { transform: translateY(-30px); }
to { transform: translateY(30px); }
}
/* Fast Foreground: 120px travel */
.depth-front {
animation: panFast linear;
animation-timeline: view();
}
@keyframes panFast {
from { transform: translateY(-80px); }
to { transform: translateY(80px); }
}
Step 3: Fine-Tuning Animation Range Boundaries
Use animation-range to define precisely when motion starts and stops: cover 0% 100% spans the entire journey across the screen, while contain 0% 100% animates only while fully inside the viewport.
.hero-card {
animation: heroRise linear;
animation-timeline: view();
/* Animates only while entering until fully visible */
animation-range: entry 0% entry 100%;
}
@keyframes heroRise {
from { opacity: 0; transform: translateY(60px) scale(0.9); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
Step 4: Fallback for Legacy Browsers without Scroll-Jank
Provide an accessible feature query with @supports (animation-timeline: view()). For older browsers, keep elements in their natural resting layout rather than injecting heavy scroll event listeners that cause jank.
@supports not (animation-timeline: view()) {
.parallax-layer-bg,
.depth-back,
.depth-front {
/* Safe resting position for legacy clients */
transform: none;
animation: none;
}
}
Next-Level Addons: Elevating Your Implementation
Take this technique further by combining it with complementary design token studios and animation tools:
A trick I use in almost every project: don't fight specificity battles with !important. Leverage modern CSS cascade layers (@layer) and CSS variables as design tokens—it makes dark/light theme switching and responsive tuning effortless.
Frequently Asked Questions
Practical answers to common implementation questions, browser quirks, and performance tips.
Why is CSS animation-timeline: view() faster than JavaScript window.scrollY listeners?
JavaScript `scroll` listeners execute on the main thread and force synchronous layout measurements (`getBoundingClientRect()`), creating severe frame drops and jank. CSS view timelines run entirely on the browser's GPU compositor thread with zero main-thread overhead.
What is the difference between animation-timeline: scroll() and view()?
`scroll()` links animation progress to the overall scrollbar position of the scroll container (from 0% at the top of the page to 100% at the bottom). `view()` links animation progress to an element's entry and exit across the visible viewport.
What is the default animation-range for a view timeline?
The default range is `cover 0% 100%`, which begins the instant the leading edge of the element touches the viewport and finishes the moment the trailing edge leaves the opposite side.
Can parallax cause motion sickness (vestibular disorders)?
Yes! Disorienting movement speeds can trigger nausea. Always include a `@media (prefers-reduced-motion: reduce)` media query that disables parallax translations and sets `transform: none`.
Do view timelines work inside horizontally scrolling carousels?
Yes! View timelines automatically track elements across the container's active scroll axis, whether horizontal (`x`) or vertical (`y`).