CSS animation-range Property
The animation-range shorthand property specifies the start and end of an animation's attachment range along a scroll-driven animation timeline.
It combines animation-range-start and animation-range-end into one declaration. This allows an animation to progress during a selected portion of a scroll or view timeline, rather than necessarily using the entire timeline.
animation-range Syntax
selector {
animation-range: entry 0% exit 100%;
}
The first value defines where the animation starts, and the second defines where it ends. A value can use a named timeline range, an offset, or a combination of both.
.default-range {
animation-range: normal;
}
.full-range {
animation-range: cover;
}
.entry-range {
animation-range: entry;
}
.custom-range {
animation-range: entry 25% exit 75%;
}
.percentage-range {
animation-range: 20% 80%;
}
The property also accepts CSS-wide values such as inherit, initial, revert, revert-layer, and unset.
Because this is a shorthand, setting animation-range assigns values to both animation-range-start and animation-range-end.
Property Values
| Value | Description |
|---|---|
normal |
Uses the normal start and end boundaries of the animation timeline. This is the initial value. |
cover |
Uses the entire cover range of a view timeline. |
contain |
Uses the portion of a view timeline where the subject is fully contained within the viewing area, or the corresponding containment range for a larger subject. |
entry |
Uses the range during which the subject enters the viewing area. |
exit |
Uses the range during which the subject leaves the viewing area. |
entry-crossing |
Uses the range during which the subject's leading edge crosses the viewing area. |
exit-crossing |
Uses the range during which the subject's trailing edge crosses the viewing area. |
20% 80% |
Starts at 20% and ends at 80% of the associated timeline. |
entry 25% exit 75% |
Starts one-quarter of the way through the entry range and ends three-quarters of the way through the exit range. |
Named ranges can be combined with percentages or supported length values to select specific attachment points.
The property applies to all elements, is not inherited, and has an initial value of normal. As a shorthand, it does not have a separate computed value; its longhand properties determine the computed values.
The animation-range property itself is not animatable.
How animation-range Works
Traditional CSS animations generally progress according to elapsed time. Scroll-driven animations instead use progress along a scroll or view timeline.
The animation-range property determines which portion of that timeline corresponds to the animation's active range.
@keyframes reveal {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.reveal-box {
animation-name: reveal;
animation-duration: auto;
animation-timing-function: linear;
animation-fill-mode: both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}
In supporting browsers, the animation progresses while the element enters the viewing area. It reaches its ending keyframe when the entry range finishes.
The animation-timeline property selects the timeline, while animation-range selects the portion of that timeline used by the animation.
Using animation-duration: auto allows the animation to use the duration determined by its scroll-driven timeline and attachment range.
Named Timeline Ranges
View timelines provide named ranges that describe the position of an element relative to a scroll container's viewing area.
cover
The cover range begins when the subject first enters the viewing area and ends when it has completely left.
.box {
animation-range: cover;
}
contain
The contain range represents the interval in which the subject is fully visible. If the subject is larger than the viewing area, it instead covers the interval in which the viewing area is fully covered by the subject.
.box {
animation-range: contain;
}
entry and exit
The entry range tracks the subject entering the viewing area. The exit range tracks the subject leaving it.
.entering {
animation-range: entry;
}
.leaving {
animation-range: exit;
}
entry-crossing and exit-crossing
The entry-crossing and exit-crossing ranges describe the intervals during which the subject's leading and trailing edges cross the viewing area.
.entering-edge {
animation-range: entry-crossing;
}
.leaving-edge {
animation-range: exit-crossing;
}
For smaller subjects, some named ranges may cover identical intervals. Their differences become more noticeable when the subject is larger than the viewing area.
Start and End Positions
Using two values allows you to choose different starting and ending points within the timeline.
.box {
animation-range: entry 25% exit 75%;
}
The animation begins at 25% of the entry range and finishes at 75% of the exit range.
Percentages associated with named ranges are measured relative to those named ranges, not necessarily the entire scroll timeline.
Using Percentages
.box {
animation-range: 20% 80%;
}
This declaration attaches the animation to the interval between 20% and 80% of the timeline's progress.
Using a Single Named Range
.box {
animation-range: entry;
}
A single named range without an offset selects the start and end boundaries of that named range.
Using Different Named Ranges
.box {
animation-range: entry 0% exit 100%;
}
This example begins at the start of the entry range and finishes at the end of the exit range, covering the subject's passage through the viewing area.
The start and end positions should be selected carefully so the animation progresses over a useful interval.
Scroll and View Timelines
The animation-range property works with scroll-driven timelines, including scroll progress timelines and view progress timelines.
Scroll Progress Timeline
A scroll progress timeline tracks how far a scroll container has been scrolled.
.progress-bar {
transform-origin: left;
animation: grow linear both;
animation-timeline: scroll();
animation-range: 0% 100%;
}
@keyframes grow {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
Here, the progress bar grows as the associated scroll container moves from the beginning to the end of its scrollable range.
View Progress Timeline
A view progress timeline tracks a subject's position as it moves through the viewing area.
.reveal-box {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}
This animation is attached to the element's entry range rather than the entire scrollable distance.
Named ranges such as entry, exit, and contain are intended for view timelines. Scroll progress timelines commonly use percentages or other supported offsets.
Multiple Animation Ranges
An element can have several animations with different attachment ranges.
.animated-element {
animation-name: fade-in, slide-in;
animation-duration: auto;
animation-timing-function: linear;
animation-timeline: view(), view();
animation-range: entry 0% entry 100%, cover 20% cover 80%;
}
The first animation progresses through the entry range. The second progresses between 20% and 80% of the cover range.
Animation ranges are matched to the animations in the order specified by animation-name.
When using multiple animations, keep the order of the names, timelines, and ranges consistent to avoid assigning an unintended range to an animation.
animation-range Example
The following example compares two view timeline attachment ranges. Scroll inside the example to see how each square responds as it enters the viewing area.
The first square uses the entry range, while the second uses the cover range. Both animate their opacity and horizontal position.
<div class="range-demo">
<div class="range-spacer">Scroll down to reveal the animations</div>
<div class="range-item">
<strong>entry</strong>
<div class="range-box entry"></div>
</div>
<div class="range-spacer">Continue scrolling</div>
<div class="range-item">
<strong>cover</strong>
<div class="range-box cover"></div>
</div>
<div class="range-spacer">End of example</div>
</div>
.range-demo {
height: 250px;
overflow-y: auto;
border: 1px solid #ccc;
background-color: #f8f9fa;
}
.range-spacer {
min-height: 220px;
display: flex;
align-items: center;
justify-content: center;
padding: 15px;
box-sizing: border-box;
color: #555;
text-align: center;
}
.range-item {
min-height: 120px;
padding: 15px;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
background-color: #fff;
}
.range-item strong {
display: block;
margin-bottom: 12px;
}
.range-box {
width: 50px;
height: 50px;
background-color: #1769aa;
}
@keyframes range-reveal {
from {
opacity: 0;
transform: translateX(0);
}
to {
opacity: 1;
transform: translateX(100px);
}
}
@supports (animation-timeline: view()) and (animation-range: entry) {
.range-box {
animation-name: range-reveal;
animation-duration: auto;
animation-timing-function: linear;
animation-fill-mode: both;
animation-timeline: view();
}
.range-box.entry {
animation-range: entry;
}
.range-box.cover {
animation-range: cover;
}
}
@media (prefers-reduced-motion: reduce) {
.range-box {
animation: none;
}
}
The example uses a scrollable container so the view timeline can respond to scrolling without requiring the entire page to move.
With entry, the first square completes its animation as it enters the viewing area. With cover, the second square progresses over the longer interval from first entering until completely leaving the viewing area.
If the browser does not support the required scroll-driven animation features, the squares remain visible and stationary. They also remain stationary when reduced motion is enabled.
Shorthand and Longhand Properties
The animation-range shorthand combines two longhand properties:
animation-range-startspecifies where the animation's attachment range begins.animation-range-endspecifies where the animation's attachment range ends.
For example, this shorthand:
.box {
animation-range: entry 25% exit 75%;
}
Is equivalent to:
.box {
animation-range-start: entry 25%;
animation-range-end: exit 75%;
}
Use the shorthand when setting both boundaries together. Use the longhand properties when only one boundary needs to change.
Unlike animation-range, the general animation shorthand does not set the animation attachment range. Declare animation-range separately.
Important Considerations
Keep the following points in mind when using animation-range:
- Scroll-driven timelines: The property is designed to control attachment ranges on scroll and view timelines, not to replace ordinary time-based animation durations.
- Timeline selection: Use
animation-timelineto establish the timeline that drives the animation. - Named ranges: Values such as
entry,exit, andcoverdescribe specific phases of a view timeline. - Offsets: Percentages and supported lengths can adjust where an animation starts or ends within a timeline.
- Shorthand behavior: Setting
animation-rangeassigns bothanimation-range-startandanimation-range-end. - Declaration order: The
animationshorthand resetsanimation-timelinetoauto. Place the timeline declaration after the shorthand. - Browser compatibility: Scroll-driven animation features are newer than traditional CSS animations and may not work in all browsers.
- Accessibility: Respect
prefers-reduced-motionand provide usable content when scroll-driven animations are unavailable.
Use animation-range when an animation should respond to a specific part of the scrolling experience, such as revealing content as it enters the viewport or updating a progress indicator.
Browser Support
The animation-range property has Limited availability and is not supported consistently across all major browsers.
Support depends on the browser's implementation of scroll-driven animations, including scroll and view timelines. Browsers that support traditional CSS keyframe animations do not necessarily support this property.
Use feature detection with @supports and provide a readable fallback when the property is unavailable.
@supports (animation-timeline: view()) and (animation-range: entry) {
.box {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry;
}
}
Visit Can I Use? to check current browser compatibility.
Specifications
The animation-range property is defined in the CSS Scroll-Driven Animations Level 1 specification.
