CSS scroll-driven animations

The CSS scroll-driven animations module provides functionality that builds on the CSS animations module and Web Animations API. It allows you to animate property values along a scroll-based timeline rather than the default time-based document timeline. This means that you can animate an element by scrolling the element, its scroll container, or its root element, rather than just by the passing of time.

Scroll-driven animations in action

You can define the scroller that controls the animation either by naming the animation or with the scroll function.

css
main {
  scroll-timeline: --mainTimeline;
}

div {
  animation: backgroundAnimation linear;
  animation-timeline: scroll(nearest inline);
}

div::after {
  animation: shapeAnimation linear;
  animation-timeline: --mainTimeline;
}

Scroll the element in the inline direction to see its background color change. Scroll it vertically to see the generated content move, spin, and change colors.

Reference

Properties

Data types and values

Functions

Interfaces

Guides

Scroll-driven animation timelines

Scroll-driven animation timelines and creating scroll-driven animations.

Specifications

Specification
Scroll-driven Animations

See also