Color scheme

Scroll-Driven Animations

Every scroll-triggered animation effect you have ever built with JavaScript shares the same basic shape: listen for the scroll event, calculate how far the user has scrolled, and update some property accordingly. Scroll-driven animations replace that entire pattern with CSS. You write a @keyframes rule, attach it to a scroll timeline instead of a time duration, and the browser handles the rest, with no event listeners, no requestAnimationFrame loops, and no JavaScript at all.

Browser Support: Chrome 115+, Edge 115+, Safari 26+

Scroll-driven animations are supported in Chrome, Edge, Opera, and Safari 26 (released 2025). Firefox has fully implemented the feature but it is not yet enabled by default. Real-world Firefox users need to manually toggle layout.css.scroll-driven-animations.enabled in about:config to use it, though it is enabled by default in Firefox Nightly. Global support sits at roughly 83%. Always provide a graceful fallback so the page is fully usable without the animations, and declare animation-timeline as a separate property rather than embedding it in the animation shorthand, which has lower support still at around 70%.

How Scroll Timelines Replace Time

A normal CSS animation plays over a fixed duration measured in milliseconds. A scroll-driven animation plays over a scroll range instead: the animation's progress is tied directly to how far something has been scrolled. At the start of the scroll range, the animation is at 0%. At the end, it is at 100%. Scrubbing back up reverses it.

The property that makes this work is animation-timeline. It accepts two timeline functions: scroll() and view(). They answer different questions about scroll position.

  • scroll() tracks how far a scroll container has been scrolled from top to bottom. Use it for things like a reading progress bar that fills as the page scrolls.
  • view() tracks how far a specific element has traveled through a scroll container's viewport. Use it for entrance and exit effects that trigger as an element comes into and leaves view.

Because animation-timeline replaces time as the driver, you omit animation-duration when using it, or set it to auto. The duration is now defined by the scroll range, not by milliseconds.

scroll(): Tracking a Scroll Container

The scroll() function creates a timeline based on the scroll progress of a scroll container. Its full syntax accepts two optional arguments: a scroller reference and an axis.


    /* scroll(scroller axis) */
    animation-timeline: scroll();           /* nearest scroll ancestor, block axis */
    animation-timeline: scroll(root);       /* the page's root scroll container */
    animation-timeline: scroll(root block); /* explicit: root, vertical axis */
    animation-timeline: scroll(self inline); /* the element itself, horizontal */

The scroller argument can be nearest (default), root, or self. The axis argument can be block (default, vertical in horizontal writing modes), inline (horizontal), x, or y. For a standard vertical page scroll, scroll(root) is the most common form.

Demo: Reading Progress Bar

The progress bar below fills from left to right as you scroll down this page. It uses scroll(root) as its timeline so it tracks the root scroll container, and scaleX as the animated property so the transform stays compositor-friendly.

A progress bar is now fixed to the top of this page. Scroll down and back up to see it track your position. The CSS that powers it:

@keyframes progress-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.scroll-progress-bar {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  block-size: 4px;
  transform-origin: left center;
  transform: scaleX(0);

  animation: progress-fill linear both;
  animation-timeline: scroll(root);
}

view(): Tracking an Element Through the Viewport

The view() function creates a timeline based on an element's position within a scroll container's viewport. Rather than tracking how far the container has scrolled overall, it tracks when the element enters, moves through, and exits the visible area. The animation runs from 0% when the element's leading edge enters the viewport to 100% when its trailing edge has fully exited.


    /* view(axis inset) */
    animation-timeline: view();             /* block axis, no inset */
    animation-timeline: view(block);        /* explicit axis */
    animation-timeline: view(block 100px);  /* uniform inset on both ends */
    animation-timeline: view(block 20% 0);  /* different inset: start 20%, end 0 */

The optional inset argument adjusts when the element is considered "in view." A positive inset shrinks the active range, meaning the animation starts later (further into the viewport) and ends earlier. This is useful for reveal animations where you want the element to be comfortably visible before the animation completes, rather than firing right at the viewport edge.

animation-range: Controlling When the Animation Fires

By default a view() timeline covers the element's entire journey from entering to exiting the viewport. Most entrance animations should only play during the entry phase, not reverse as the element scrolls out. The animation-range property lets you specify exactly which portion of the timeline to use.


    /* Named range keywords */
    animation-range: entry;         /* from first pixel entering to fully entered */
    animation-range: exit;          /* from start of exit to fully out of view */
    animation-range: cover;         /* entire time any part of element is visible */
    animation-range: contain;       /* only when element is fully inside viewport */

    /* Percentage within a range */
    animation-range: entry 0% entry 50%;  /* first half of the entry phase only */

For a fade-in reveal effect, animation-range: entry combined with animation-fill-mode: both is the standard pattern: the element starts invisible, animates to visible as it enters, and stays visible after the range ends.

Demo: Card Reveal on Scroll

The cards below use view() with animation-range: entry to fade and slide up as they enter the viewport. Each card animates independently as it crosses the visible area. In standard Firefox releases where the flag is not enabled, the cards appear at their final visible state immediately.

Card One

Fades and slides up as it enters the viewport. Uses animation-range: entry 0% entry 60% so the animation completes before the card is fully in view.

Card Two

Each card has its own independent view() timeline. Scroll slowly to watch each one trigger separately.

Card Three

Because animation-fill-mode: both is applied, cards start invisible (before entry) and stay visible after the range ends.

Card Four

In standard Firefox releases, this card appears immediately at full opacity since scroll-driven animations are behind a flag by default. The fallback is a fully visible, functional card.

Reduced Motion and Scroll Animations

Scroll-driven animations are still animations. An element that slides up on scroll is just as capable of triggering vestibular symptoms as one that slides on a timer. Apply prefers-reduced-motion guards the same way you would for any other motion.

The no-preference containment pattern works especially well here because scroll-driven animations degrade cleanly: wrap your animation and animation-timeline declarations inside @media (prefers-reduced-motion: no-preference) and the element simply appears at its final state for users who prefer reduced motion. No override needed because there is nothing to override.


    /* The element starts at its visible final state by default */
    .reveal-card {
        opacity: 1;
        transform: translateY(0);
    }

    /* Motion only applies when the user has not opted out */
    @media (prefers-reduced-motion: no-preference) {
        @keyframes card-reveal {
            from { opacity: 0; transform: translateY(24px); }
            to   { opacity: 1; transform: translateY(0); }
        }

        .reveal-card {
            animation: card-reveal ease-out both;
            animation-timeline: view();
            animation-range: entry 0% entry 60%;
        }
    }
Firefox Gets the Fallback for Free

The no-preference containment pattern also serves as your Firefox fallback for users who have not enabled the flag. Since scroll-driven animations are not active by default in standard Firefox releases, the animation-timeline declaration is ignored and the element stays at its default visible state. One pattern handles reduced-motion users, unsupported browsers, and Firefox users with the default configuration without any extra code.

Build Your Demo

You have two options for where to build your portfolio demo. Choose the one that fits where you are in the unit:

  • Combine: Add scroll-driven animations directly to your motion prove assignment page at unit-6/motion/index.html. Extend the existing motion.css file with your scroll-driven additions.
  • Standalone: Create a new directory at unit-6/scroll-driven/ with index.html and scroll-driven.css. Build a page long enough to scroll meaningfully, with at least one scroll() effect and one view() effect.

Whichever path you choose, your demo must include:

  • At least one scroll() animation tied to the root scroll container (a progress bar is a natural fit, but not required).
  • At least one view() animation using animation-range to control which phase of the element's scroll journey triggers the animation.
  • A prefers-reduced-motion guard on all scroll-driven animations, using a pattern that also serves as a graceful Firefox fallback.
  • Only compositor-friendly properties (transform and opacity) inside animated @keyframes rules.

Add a link to your demo page on your portfolio homepage and in your README.md if you went the standalone route.

Teaching Video Checklist

When you record your teaching video, make sure your teammates come away understanding these concepts:

  • What animation-timeline does and why it replaces time as the driver of the animation, connecting the concept to the scroll listener pattern it replaces.
  • The difference between scroll() and view(): one tracks how far a container has scrolled, the other tracks where a specific element is within the viewport.
  • What animation-range does and why it matters for entrance effects, including at least one concrete example of what happens without it versus with it.
  • Why the no-preference containment pattern is especially clean for scroll-driven animations, and how it handles both reduced-motion users and Firefox in a single block.
  • Your portfolio demo: show both a scroll() effect and a view() effect running on your actual page, and walk through the CSS that drives each one.

Start by showing what the page looks like with the animations present, then open DevTools, toggle the reduced-motion emulation, and show teammates how the same page behaves for a user who prefers reduced motion. The contrast makes the accessibility argument concrete.

Resources