CSS Reference ยท Transforms, Transitions and Animations
The animation-timeline property
Reference for the CSS animation-timeline property: drive an animation by scroll position or element visibility with scroll(), view() or a named timeline.
The animation-timeline property chooses what drives an animation's progress. By default that is time: the animation advances as the clock ticks. With a scroll or view timeline, progress follows how far a container has been scrolled, or how far an element has travelled through the visible area. This is the basis of scroll-driven animations.
You can pass an anonymous timeline with scroll() or view(), or the name of a timeline declared with scroll-timeline or view-timeline.
.progress { animation: grow linear both; animation-timeline: scroll(); }
Try it
Syntax
animation-timeline: auto | none | <dashed-ident> | scroll() | view(); scroll( [ nearest | root | self ] || [ block | inline | x | y ] ) view( [ block | inline | x | y ] || <'view-timeline-inset'> ) /* one value per animation name */ animation-timeline: scroll(root), view();
- Initial value:
auto - Applies to: all elements,
::beforeand::after - Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
The default document timeline: time drives the animation. |
none |
No timeline, so the animation does not run. |
<dashed-ident> |
The name of a timeline from scroll-timeline or view-timeline on this element or an ancestor (names start with --). |
scroll() |
An anonymous scroll progress timeline. The first keyword picks the scroller (nearest ancestor scroll container by default, root for the page, self). The second picks the axis (block by default, inline, x or y). |
view() |
An anonymous view progress timeline for this element in its nearest scroll container. Takes an optional axis and inset. |
Usage notes
- Declare the timeline after the
animationshorthand. The shorthand resetsanimation-timelinetoauto, so a timeline set earlier would be lost. - Use
lineareasing. Scroll progress should map straight to animation progress. The defaulteasemakes the effect feel like it lags and overshoots. - Duration is irrelevant for scroll-linked animations: progress comes from the timeline. Some browsers still want a non-zero value;
autois the modern default. - Range. By default the whole timeline is used. Use
animation-rangeto run the animation over only part of it. - Use
bothfill. Before and after the active range,animation-fill-mode: bothkeeps the first or last keyframe in place. - Prefer compositor-friendly properties such as
transformandopacityso scrolling stays smooth. - Accessibility. Parallax and large movement tied to scrolling can cause discomfort. Gate them with
@media (prefers-reduced-motion: no-preference). - Feature detection. Wrap the declarations in
@supports (animation-timeline: scroll())and make sure content stays visible when the property is unsupported. Never start content atopacity: 0outside the supports block.
Browser support
Scroll-driven animations are a newer feature and support is not uniform across browsers. Chromium-based browsers have supported them for some time, others have followed or are behind flags, so check a compatibility table and use @supports as a progressive enhancement.
Related
animation-rangeโ the part of the timeline usedscroll-timelineandview-timelineโ named timelinestimeline-scopeโ sharing named timelinesanimation- Lesson: Scroll-driven animations