This feature is not Baseline because it does not work in some of the most widely-used browsers.
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:
auto, or by not specifying an animation-timeline value at all.scroll-timeline-name property (or the scroll-timeline shorthand property). The name is then linked to the element to animate by specifying it as the value of that element's animation-timeline property.scroll() function as an animation-timeline value, which selects the scroller providing the scroll progress timeline and the scroll axis to be used based on the arguments you pass to it.view-timeline-name property (or the view-timeline shorthand property). The name is then linked to the element to animate by specifying it as the value of that element's animation-timeline property. This is a key point — with named view progress timelines, the element to animate does not have to be the same as the subject.view() function as an animation-timeline value, causing it to be animated based on its position inside its nearest parent scroller.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.
/* Keyword */ animation-timeline: none; animation-timeline: auto; /* Single animation named timeline */ animation-timeline: --timeline_name; /* Single animation anonymous scroll progress timeline */ animation-timeline: scroll(); animation-timeline: scroll(scroller axis); /* Single animation anonymous view progress timeline */ animation-timeline: view(); animation-timeline: view(axis inset); /* Multiple animations */ animation-timeline: --progress-bar-timeline, --carousel-timeline; animation-timeline: none, --sliding-timeline; /* Global values */ animation-timeline: inherit; animation-timeline: initial; animation-timeline: revert; animation-timeline: revert-layer; animation-timeline: unset;
noneThe animation is not associated with a timeline.
autoThe animation's timeline is the document's default DocumentTimeline.
scroll()An anonymous scroll progress timeline is provided by some ancestor scroller of the current element. The function parameters allow you to select the scroller, and the scrolling axis the timeline will be measured along.
See scroll() for more information.
view()An anonymous view progress timeline is provided by the subject that animation-timeline: view(); is set on. The function parameters allow you to select the scrollbar axis along which timeline progress will be tracked and an inset that adjusts the position of the box in which the subject is deemed to be visible.
See view() for more information.
<dashed-ident>A <dashed-ident> identifying a named timeline previously declared with the scroll-timeline-name or view-timeline-name property (or the scroll-timeline or view-timeline shorthand property).
Note: If two or more timelines share the same name, the last declared within the cascade will be used. Also, if no timeline is found that matches the given name, the animation is not associated with a timeline.
Note: The <dashed-ident> values must start with --. This helps avoid name clashes with standard CSS keywords.
| Initial value | auto |
|---|---|
| Applies to | all elements |
| Inherited | no |
| Computed value | a list, each item either a case-sensitive CSS identifier or the keywords none, auto
|
| Animation type | Not animatable |
animation-timeline =
<single-animation-timeline>#
<single-animation-timeline> =
auto |
none |
<dashed-ident> |
<scroll()> |
<view()>
<scroll()> =
scroll( [ <scroller> || <axis> ]? )
<view()> =
view( [ <axis> || <'view-timeline-inset'> ]? )
<scroller> =
root |
nearest |
self
<axis> =
block |
inline |
x |
y
<view-timeline-inset> =
[ [ auto | <length-percentage> ]{1,2} ]#
<length-percentage> =
<length> |
<percentage>
A scroll progress timeline named --square-timeline is defined using the scroll-timeline-name property on an element with an id of container. This is then set as the timeline for the animation on the #square element using animation-timeline: --square-timeline.
The HTML for the example is shown below.
<div id="container"> <div id="square"></div> <div id="stretcher"></div> </div>
The CSS for the container sets it as the source of a scroll progress timeline named --square-timeline using the scroll-timeline-name property (we could explicitly set which scrollbar axis to use with scroll-timeline-axis, but there is only a block direction scrollbar here, and it will be used by default).
The height of the container is set to 300px and we also set the container to create a vertical scrollbar if it overflows (below we will use CSS on the "stretcher" element to ensure that it does overflow).
#container {
height: 300px;
overflow-y: scroll;
scroll-timeline-name: --square-timeline;
position: relative;
}
The CSS below defines a square that rotates in alternate directions according to the timeline provided by the animation-timeline property, which is set to the --square-timeline timeline named above.
#square {
background-color: deeppink;
width: 100px;
height: 100px;
margin-top: 100px;
animation-name: rotateAnimation;
animation-duration: 1ms; /* Firefox requires this to apply the animation */
animation-direction: alternate;
animation-timeline: --square-timeline;
position: absolute;
bottom: 0;
}
@keyframes rotateAnimation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
The "stretcher" CSS sets the block height to 600px, which forces the container element to overflow and create scroll bars. Without this element there would be no scrollbar, and hence no scroll progress timeline to associate with the animation timeline.
#stretcher {
height: 600px;
}
Scroll to see the square element being animated.
In this example, the #square element is animated using an anonymous scroll progress timeline, which is applied to the element to be animated using the scroll() function. The timeline in this particular example is provided by the nearest parent element that has (any) scrollbar, from the scrollbar in the block direction.
The HTML for the example is shown below.
<div id="container"> <div id="square"></div> <div id="stretcher"></div> </div>
The CSS below defines a square that rotates in alternate directions according to the timeline provided by the animation-timeline property. In this case, the timeline is provided by scroll(block nearest), which means that it will select the scrollbar in the block direction of the nearest ancestor element that has scrollbars; in this case the vertical scrollbar of the "container" element.
Note: block and nearest are actually the default parameter values, so we could have used just scroll().
#square {
background-color: deeppink;
width: 100px;
height: 100px;
margin-top: 100px;
position: absolute;
bottom: 0;
animation-name: rotateAnimation;
animation-duration: 1ms; /* Firefox requires this to apply the animation */
animation-direction: alternate;
animation-timeline: scroll(block nearest);
}
@keyframes rotateAnimation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
The CSS for the container sets its height to 300px and we also set the container to create a vertical scrollbar if it overflows. The "stretcher" CSS sets the block height to 600px, which forces the container element to overflow. These two together ensure that the container has a vertical scrollbar, which allows it to be used as the source of the anonymous scroll progress timeline.
#container {
height: 300px;
overflow-y: scroll;
position: relative;
}
#stretcher {
height: 600px;
}
Scroll to see the square element being animated.
A view progress timeline named --subject-reveal is defined using the view-timeline-name property on a subject element with a class of animation. This is then set as the timeline for the same element using animation-timeline: --subject-reveal;. The result is that the subject element animates as it moves upwards through the document as it is scrolled.
The HTML for the example is shown below.
<div class="content">
<h1>Content</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam
quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat
interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat
vivamus at augue.
</p>
<p>
Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate
dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna
duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus.
Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum
arcu vitae elementum curabitur vitae nunc sed velit.
</p>
<div class="subject animation"></div>
<p>
Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu
cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet
dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non
tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam
vel quam elementum. Nibh praesent tristique magna sit amet purus gravida
quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat
imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi
scelerisque. Netus et malesuada fames ac.
</p>
</div>
The subject element and its containing content element are styled minimally, and the text content is given some basic font settings:
.subject {
width: 300px;
height: 200px;
margin: 0 auto;
background-color: deeppink;
}
.content {
width: 75%;
max-width: 800px;
margin: 0 auto;
}
p,
h1 {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
font-size: 3rem;
}
p {
font-size: 1.5rem;
line-height: 1.5;
}
The <div> with the class of subject is also given a class of animation — this is where the view-timeline-name is set to define a named view progress timeline. It is also given an animation-timeline name with the same value to declare that this will be the element animated as the view progress timeline is progressed.
Lastly, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller.
.animation {
view-timeline-name: --subject-reveal;
animation-timeline: --subject-reveal;
animation-name: appear;
animation-fill-mode: both;
animation-duration: 1ms; /* Firefox requires this to apply the animation */
}
@keyframes appear {
from {
opacity: 0;
transform: scaleX(0);
}
to {
opacity: 1;
transform: scaleX(1);
}
}
Scroll to see the subject element being animated.
An anonymous view progress timeline is set on an element with class subject using animation-timeline: view(). The result is that the subject element animates as it moves upwards through the document as it is scrolled.
The HTML for the example is shown below.
<div class="content">
<h1>Content</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam
quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat
interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat
vivamus at augue.
</p>
<p>
Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate
dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna
duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus.
Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum
arcu vitae elementum curabitur vitae nunc sed velit.
</p>
<div class="subject animation"></div>
<p>
Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu
cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet
dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non
tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam
vel quam elementum. Nibh praesent tristique magna sit amet purus gravida
quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat
imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi
scelerisque. Netus et malesuada fames ac.
</p>
</div>
The subject element and its containing content element are styled minimally, and the text content is given some basic font settings:
.subject {
width: 300px;
height: 200px;
margin: 0 auto;
background-color: deeppink;
}
.content {
width: 75%;
max-width: 800px;
margin: 0 auto;
}
p,
h1 {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
font-size: 3rem;
}
p {
font-size: 1.5rem;
line-height: 1.5;
}
The <div> with the class of subject is also given a class of animation — this is where animation-timeline: view() is set to declare that it will be animated as it progresses through the view progress timeline provided by its scrolling ancestor (in this case the document's root element).
Last, an animation is specified on the element that animates its opacity and scale, causing it to fade in and size up as it moves up the scroller.
.animation {
animation-timeline: view();
animation-name: appear;
animation-fill-mode: both;
animation-duration: 1ms; /* Firefox requires this to apply the animation */
}
@keyframes appear {
from {
opacity: 0;
transform: scaleX(0);
}
to {
opacity: 1;
transform: scaleX(1);
}
}
Scroll to see the subject element being animated.
| Specification |
|---|
| CSS Animations Level 2> # animation-timeline> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
animation-timeline |
115 | 115 | 110 | 101 | 26 | 115 | No | 77 | 26 | 23.0 | 115 | 26 |
scroll |
115 | 115 | 110["Zero scroll range is treated as 100% but should be 0% (see bug 1780865).", "Supports the deprecatedhorizontal and vertical axis values, and not the x and y values."] |
101 | 26 | 115 | No | 77 | 26 | 23.0 | 115 | 26 |
view |
115 | 115 | 114 | 101 | 26 | 115 | No | 77 | 26 | 23.0 | 115 | 26 |
animation, animation-composition, animation-delay, animation-direction, animation-duration, animation-fill-mode, animation-iteration-count, animation-name, animation-play-state, animation-timing-function
scroll-timeline-name, scroll-timeline-axis, scroll-timeline
timeline-scopeview-timeline-name, view-timeline-axis, view-timeline, view-timeline-inset
timeline property available in Element.animate() calls
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timeline