animation-range-end

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The animation-range-end CSS property is used to set the end of an animation's attachment range along its timeline, i.e., where along the timeline an animation will end.

Syntax

css
/* Keyword or length percentage value */
animation-range-end: normal;
animation-range-end: 80%;
animation-range-end: 700px;

/* Named timeline range value */
animation-range-end: cover;
animation-range-end: contain;
animation-range-end: cover 80%;
animation-range-end: contain 700px;

Values

normal

Represents the end of the timeline. This is the default value.

<length-percentage>

A length or percentage value measured from the beginning of the timeline.

<timeline-range-name>

A specific named timeline range inside the overall timeline, starting at 0%.

<timeline-range-name> <length-percentage>

A specified percentage or distance through a named timeline range, measured from the start of that timeline range.

Description

The animation-range-end property specifies the end of the animation's attachment range, potentially shifting the end time of the animation (i.e., where keyframes mapped to 100% progress are attached when the iteration count is 1) and/or reducing the duration of the animation.

The value can be normal, a <length-percentage>, or a timeline-range-name with an optional <length-percentage>. When the <timeline-range-name> value does not include a <length-percentage>, the percentage defaults to 100%.

The animation-range-end property is included in the animation shorthand as a reset-only value. This means that including animation resets a previously-declared animation-range-end value to normal, but the <animation-range-end> value cannot be set via animation. When creating CSS scroll-driven animations, you should declare animation-range-end after declaring any animation shorthand to prevent the value from being reset to normal.

The animation-range-end property (and the animation-range-start property) can also be set using the animation-range shorthand property.

Formal definition

Initial valuenormal
Applies toall elements
Inheritedno
PercentagesRelative to the specified named timeline range if specified, otherwise relative to the entire timeline
Computed valueA list where each item may be 'normal', a length percentage, or a timeline range name and a length percentage
Animation typeNot animatable

Formal syntax

animation-range-end = 
[ normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#

<length-percentage> =
<length> |
<percentage>

Examples

Creating a view progress timeline with a range end

In this example, the animation-range-end is applied to an element animated via a view progress timeline, setting the animation to reach the last keyframe well before the element reaches the end of it's containing viewport.

HTML

In the middle of a wall of text, we include an element that we will animate. We added a lot of text in to ensure that our content overflows its container, but this was hidden for the sake of brevity.

html
<div class="animatedElement"></div>

We also includes a checkbox to that will toggle the animation-fill-mode property to demonstrate the effect of this property on shortened animation timelines.

html
<label>
  <input type="checkbox" /> Add <code>animation-fill-mode: forwards;</code>
</label>

CSS

A view progress timeline is defined using setting a view() function as the value of the animation-timeline property. This is declared after the animation shorthand, so as to not reset the longhand property value.

An animation-range-end declaration is also set to make the animation end earlier than expected.

css
.animatedElement {
  background-color: deeppink;
  animation: appear 1ms linear;
  animation-timeline: view();
  animation-range-end: exit 25%;
}

@keyframes appear {
  from {
    background-color: rebeccapurple;
    opacity: 0;
    transform: scaleX(0);
  }

  to {
    background-color: darkturquoise;
    opacity: 0.75;
    transform: scaleX(0.75);
  }
}

We also include conditional styling: when the checkbox is checked, the animation-fill-mode property gets applied to the animated element:

css
:has(:checked) .animatedElement {
  animation-fill-mode: forwards;
}

The other styles were hidden for the sake of brevity.

Result

Scroll to see the element being animated. Toggle the checkbox and scroll again. Note how the element finishes animating 75% of the way through the viewport, and how it returns to its default state at this point when the animation-fill-mode property is not applied.

Specifications

Specification
Scroll-driven Animations
# animation-range-end

Browser compatibility

See also