animation-range-start
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The animation-range-start CSS property sets the point on the timeline where an animation should start.
Syntax
/* Keyword or length percentage value */
animation-range-start: normal;
animation-range-start: 20%;
animation-range-start: 100px;
/* Named timeline range value */
animation-range-start: cover;
animation-range-start: contain;
animation-range-start: cover 20%;
animation-range-start: contain 100px;
/* Global values */
animation-range-start: inherit;
animation-range-start: initial;
animation-range-start: revert;
animation-range-start: revert-layer;
animation-range-start: unset;
Values
normal-
Represents the start of the timeline. This is the default value.
<length-percentage>-
Specifies a length or percentage value measured from the beginning of the timeline.
<timeline-range-name>-
Specifies a named timeline range within the overall timeline. The range starts at
0%. <timeline-range-name> <length-percentage>-
Specifies a length or percentage value measured from the beginning of the specified named timeline range.
Description
Allowed values for the animation-range-start property are normal, a <length-percentage>, a <timeline-range-name>, or a <timeline-range-name> followed by a <length-percentage>. If the <timeline-range-name> value does not include a <length-percentage>, the percentage defaults to 0%.
See animation-range for a detailed description of the available values.
Also check out the View progress timeline visualizer, which shows what the different values mean in an easy-to-follow visual format.
The animation-range-start is included in the animation shorthand as a reset-only value. This means that using the animation shorthand resets any previously declared animation-range-start value of equal or lower specificity to normal; the shorthand cannot be used to set a new animation-range-start value. When creating CSS scroll-driven animations, you should declare animation-range-start after declaring any animation shorthand to avoid resetting the value to normal.
The animation-range-start, along with the animation-range-end property, can also be set using the animation-range shorthand.
Formal definition
| Initial value | normal |
|---|---|
| Applies to | all elements |
| Inherited | no |
| Percentages | Relative to the specified named timeline range if specified, otherwise relative to the entire timeline |
| Computed value | A list where each item may be 'normal', a length percentage, or a timeline range name and a length percentage |
| Animation type | Not animatable |
Formal syntax
animation-range-start =
[ normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#
<length-percentage> =
<length> |
<percentage>
Examples
>Creating a scroll view progress timeline with range start
In this example, the animation-range-start is applied to an element animated via a scroll progress timeline. This makes the animation start well before the element enters the scrollport.
HTML
In the middle of a long block of text, we've included an element that we'll animate. We've added a lot of text to ensure that the content overflows its container; the extra text is hidden here for brevity.
<div class="animatedElement"></div>
CSS
A scroll progress timeline is defined using setting a scroll() function as the value of the animation-timeline property. This is declared after the animation shorthand to avoid resetting the longhand property value.
We've also set animation-range-start to make the animation start earlier than expected.
.animatedElement {
background-color: deeppink;
animation: appear 1ms linear;
animation-timeline: scroll();
animation-range-start: -25%;
}
@keyframes appear {
from {
background-color: rebeccapurple;
opacity: 0;
transform: scaleX(0);
}
to {
background-color: darkturquoise;
opacity: 0.75;
transform: scaleX(0.75);
}
}
Other styles applied in this example have been hidden here for brevity.
Result
Scroll to see the element animate. Notice how the element is already scaled and semi-opaque as it enters the viewport. This is because the element started animating well before it entered the viewport.
Specifications
| Specification |
|---|
| Scroll-driven Animations> # animation-range-start> |