Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The animation-timeline CSS property specifies the timeline that is used to control the progress of a CSS animation.
The following types of timelines can be set via animation-timeline:
- The default document timeline, which is progressed through by the passing of time since the document was first loaded in the browser. This is the timeline traditionally associated with CSS animations and is selected with a value of
auto, or by not specifying ananimation-timelinevalue at all. - A scroll progress timeline, which is progressed through by scrolling a scrollable element (scroller) between top and bottom (or left and right). The position in the scroll range is converted into a percentage of progress — 0% at the start and 100% at the end. The element that provides the scroll progress timeline can be specified in two ways:
- A named scroll progress timeline is one where the scroller providing the scroll progress timeline is explicitly named using the
scroll-timeline-nameproperty (or thescroll-timelineshorthand property). The name is then linked to the element to animate by specifying it as the value of that element'sanimation-timelineproperty. - An anonymous scroll progress timeline is one where the element to animate is given a
scroll()function as ananimation-timelinevalue, which selects the scroller providing the scroll progress timeline and the scroll axis to be used based on the arguments you pass to it.
- A named scroll progress timeline is one where the scroller providing the scroll progress timeline is explicitly named using the
- A view progress timeline, which is progressed through based on the change in visibility of an element (known as the subject) inside a scroller. The visibility of the subject inside the scroller is tracked — by default, the timeline is at 0% when the subject is first visible at one edge of the scroller, and 100% when it reaches the opposite edge. Unlike with scroll progress timelines, you can't specify the scroller — the subject's visibility is always tracked within its nearest ancestor scroller. The subject that provides the view progress timeline can be specified in two ways:
- A named view progress timeline is one where the subject is explicitly named using the
view-timeline-nameproperty (or theview-timelineshorthand property). The name is then linked to the element to animate by specifying it as the value of that element'sanimation-timelineproperty. This is a key point — with named view progress timelines, the element to animate does not have to be the same as the subject. - An anonymous view progress timeline is one where the subject is given a
view()function as ananimation-timelinevalue, causing it to be animated based on its position inside its nearest parent scroller.
- A named view progress timeline is one where the subject is explicitly named using the
Note: animation-timeline is included in the animation shorthand as a reset-only value. This means that including animation resets a previously-declared animation-timeline value to auto, but a specific value cannot be set via animation. When creating CSS scroll-driven animations, you need to declare animation-timeline after declaring any animation shorthand for it to take effect.