CSS Reference ยท Transforms, Transitions and Animations
The animation-range property
Reference for the CSS animation-range property: limit a scroll-driven animation to part of its timeline using entry, exit, cover, contain and offsets.
The animation-range property says which slice of a scroll or view timeline an animation uses. Without it the animation spreads over the whole timeline. With it you can say "start when the element begins to enter the viewport and finish when it is fully inside".
It is a shorthand for animation-range-start and animation-range-end, and it only has an effect on animations that use animation-timeline with a scroll or view timeline.
.card { animation: reveal linear both; animation-timeline: view(); animation-range: entry 0% entry 100%; }
Try it
Supported browsers show grey boxes turning teal and growing. Where scroll-driven animations are not available, the boxes simply stay grey.
Syntax
animation-range: [ <start> ] [ <end> ]? /* <start> and <end> */ normal <length-percentage> <named-range> <length-percentage>? /* named ranges */ cover | contain | entry | exit | entry-crossing | exit-crossing
- Initial value:
normal(the whole timeline) - Applies to: all elements,
::beforeand::after - Inherited: no
- Animatable: no
- Percentages: refer to the chosen named range, or to the whole timeline if no name is given
- Computed value: as specified, with lengths made absolute
Values
| Value | Description |
|---|---|
normal |
Use the full timeline: start at its beginning, end at its end. |
cover |
From the moment the element's box first touches the scrollport until it has completely left. |
contain |
From when the box is fully inside the scrollport until it starts to leave. Reversed when the box is larger than the scrollport. |
entry |
From first touching the scrollport until the box is fully inside. |
exit |
From the box starting to leave until it has completely left. |
entry-crossing / exit-crossing |
Variants of entry and exit that follow the moment the box's edges cross the scrollport edge. Rarely needed. |
<length-percentage> |
An offset along the timeline or inside the named range, such as 20% or 100px. |
A single named range, as in animation-range: entry, expands to that range's start and end (entry 0% entry 100%). Two values give a start and an end. A start of cover 20% means 20% into the cover range.
Usage notes
- Named ranges only exist for view timelines. On a scroll progress timeline (
scroll()) use lengths or percentages. - Mix ranges.
animation-range: entry 50% cover 50%starts halfway through entry and ends halfway through cover. - Longhands. Use
animation-range-startandanimation-range-endto change one side only. - Insets change the geometry.
view-timeline-insetmoves the edges of the scrollport used for these ranges. - Fill modes matter. Outside the range the animation is inactive. Use
animation-fill-mode: bothso the element keeps the first or last keyframe. - Check ranges visually. The easiest way to tune values is the scroll-driven animation tools in browser developer tools that visualize the ranges.
Browser support
Scroll-driven animations, including animation-range, are a recent addition and are not equally supported in all browsers. Check a compatibility table, test with @supports (animation-range: entry) and treat the effect as an enhancement.