timeline-trigger-activation-range CSS property

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The timeline-trigger-activation-range CSS shorthand property specifies a scroll-triggered animation trigger's activation range.

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

css
/* Keyword */
timeline-trigger-activation-range: normal;

/* Range start value only */
/* Single value */
timeline-trigger-activation-range: 40%;
timeline-trigger-activation-range: 200px;
timeline-trigger-activation-range: contain;
timeline-trigger-activation-range: entry;
/* Two values */
timeline-trigger-activation-range: exit 50%;
timeline-trigger-activation-range: contain 150px;

/* Range start and end values */
/* Two values */
timeline-trigger-activation-range: 20% 80%;
timeline-trigger-activation-range: entry exit;
timeline-trigger-activation-range: normal 20%;
timeline-trigger-activation-range: 20% normal;
/* Three values */
timeline-trigger-activation-range: contain contain 40%;
timeline-trigger-activation-range: 200px exit 300px;
timeline-trigger-activation-range: entry 10% 90%;
/* Four values */
timeline-trigger-activation-range: entry 0% exit 50%;
timeline-trigger-activation-range: contain 100px contain 90%;

/* Multiple ranges */
timeline-trigger-activation-range:
  contain,
  entry 0% exit 50%;

/* Global values */
timeline-trigger-activation-range: inherit;
timeline-trigger-activation-range: initial;
timeline-trigger-activation-range: revert;
timeline-trigger-activation-range: revert-layer;
timeline-trigger-activation-range: unset;

The timeline-trigger-activation-range shorthand property is specified as one or more single animation ranges, separated by commas. Each animation range is specified as a timeline-trigger-activation-range-start value, and optionally, a timeline-trigger-activation-range-end value.

Each longhand property value is specified as one of:

Values

<'timeline-trigger-activation-range-start'>

The keyword normal, a <length-percentage>, a <timeline-range-name>, or a <timeline-range-name> <length-percentage> pair, representing the timeline-trigger-activation-range-start. If a <timeline-range-name> is set without a <length-percentage>, the <length-percentage> defaults to 0%.

<'timeline-trigger-activation-range-end'>

The keyword normal, a <length-percentage>, a <timeline-range-name>, or a <timeline-range-name> <length-percentage> pair, representing the timeline-trigger-activation-range-end. If a <timeline-range-name> is set without a <length-percentage>, the <length-percentage> defaults to 100%.

Description

The timeline-trigger-activation-range property can be used to set a custom activation range for a CSS scroll-triggered animation trigger. The activation range is the range between the scrolling offset at which the trigger is activated, and the scrolling offset at which the trigger is deactivated.

By default, the activation range along the timeline is cover, which means that the trigger activates when the start edge of the tracked element enters the end edge of the viewport, and deactivates when the end edge of the tracked element has exited either edge of the viewport. This can be changed by setting a different timeline-trigger-activation-range value.

For example:

css
.trigger {
  timeline-trigger-name: --my-trigger;
  timeline-trigger-source: view();
  timeline-trigger-activation-range: entry 0% exit 50%;
}

An element with these declarations set will create a trigger with an identifying timeline-trigger-name of --my-trigger, and a timeline-trigger-source value of view(), which sets the timeline tracking the element to a view progress timeline based on its nearest scrolling ancestor element.

We also set a timeline-trigger-activation-range value of entry 100% exit 50%, which sets the start of the activation range to 100% of the way through the entry range and the end of the activation range to 50% of the way through the exit range. The result is that the animated element's trigger will activate when the tracked element has completely entered the viewport, and deactivate when 50% of the tracked element has left the viewport.

An animated element can be triggered by the previously-described trigger by referencing the trigger's identifying name in its animation-trigger property.

For example:

css
.animated {
  animation: rotate 3s infinite linear both;
  animation-trigger: --my-trigger play-forwards play-backwards;
}

In this case, the animation will be triggered by the trigger with the timeline-trigger-name of --my-trigger. Its <animation-action> keywords — play-forwards play-backwards — specify that the animation should play forwards on activation, and backwards on deactivation.

Note: The timeline-trigger-activation-range property can also be set via the timeline-trigger shorthand property.

Note: It is possible for the animated element and the element that creates the trigger to be the same element.

Optionally, you can also set a longer active range, which is the range in which the trigger stays active before it deactivates, using the timeline-trigger-active-range shorthand property or its longhands.

timeline-trigger-activation-range value explanation

In terms of explicit and default values, timeline-trigger-activation-range works in exactly the same way as the animation-range property. In this section we will provide a brief explanation and then link to the appropriate sections on that page for more details.

If two values are specified as components of the timeline-trigger-activation-range property, they will be interpreted in the order timeline-trigger-activation-range-start then timeline-trigger-activation-range-end.

The value of each component can be one of the following:

  • The keyword normal, which is equivalent to 0% for start and 100% for end.
  • A <length-percentage>, which sets a specific length or percentage through the default cover range.
  • A <timeline-range-name>, which sets a different timeline range with an implicit percentage of 0% for start and 100% for end.
  • A <timeline-range-name> followed by a <length-percentage>, which sets a specific percentage through a different timeline range. These values are space-separated.

See Explicitly defining both range start and range end with two values for more information.

When defining a timeline-trigger-activation-range-start value explicitly and letting the timeline-trigger-activation-range-end value adopt a default value, what the default value is depends on the supplied start value, and the rules to determine this are complex. Read Defining range start and defaulting range end for more details.

Specifying multiple ranges

When multiple ranges are specified in a single timeline-trigger-activation-range property, they are distributed between the specified timeline-trigger-name values in the same fashion as multiple animation values are distributed (see Setting multiple animation property values).

If multiple timeline-trigger-name values are set, but only a single timeline-trigger-activation-range value is set, the timeline-trigger-activation-range will apply to all the timeline-trigger-names. If two timeline-trigger-activation-range values are set, they will cycle between the timeline-trigger-names until all of them have a timeline-trigger-activation-range value set. And so on.

For example, consider these declarations:

css
timeline-trigger-name: --my-trigger, --my-other-trigger, --another-trigger;
timeline-trigger-activation-range:
  contain,
  entry 0% exit 50%;

In this case, the first name will use the contain range, and the second name will use the entry 0% exit 50% range. The third name will cycle back to using the contain range again.

Formal definition

Value not found in DB!

Formal syntax

timeline-trigger-activation-range = 
[ <'timeline-trigger-activation-range-start'> <'timeline-trigger-activation-range-end'>? ]#

<timeline-trigger-activation-range-start> =
[ normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#

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

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

Examples

Basic usage

In this example, we show how to create a basic scroll-triggered animation with a custom activation range.

HTML

Our markup contains two <div> elements, plus some basic text content to cause the page to scroll. We have hidden the text content for brevity.

html
<div class="animated">I am animated</div>

...

<div class="trigger">I create the trigger</div>

...

CSS

The .animated <div> element has an animation applied that rotates it. We set an animation-trigger value on it that references a trigger name of --t; we also specify two <animation-action> values — play and pause — which specify that the animation will play on activation, and pause on deactivation.

The .trigger <div> element creates the animated <div>'s trigger using:

  • A timeline-trigger-name value of --t, which is equal to the identifier referenced in the animated <div>'s animation-trigger property value, associating the two together.
  • A timeline-trigger-source value of view(), which sets the timeline trigger as a view progress timeline, and the element providing the timeline trigger as the nearest scrolling ancestor element.
  • A timeline-trigger-activation-range of entry 50% exit 50%, which sets the trigger's activation range to a range between 50% through the entry range (when 50% of the tracked element has entered the viewport) and 50% through the exit range (when 50% of the tracked element has exited the viewport).
css
div.animated {
  animation: rotate 3s infinite linear both;
  animation-trigger: --t play pause;
}

div.trigger {
  timeline-trigger-name: --t;
  timeline-trigger-source: view();
  timeline-trigger-activation-range: entry 50% exit 50%;
}

Next, we give the animated <div> a position of fixed, positioning it near the top-left of the viewport so that we can easily see when its animation starts and stops.

css
div.animated {
  position: fixed;
  top: 25px;
  left: 25px;
}

Finally, we define the @keyframes for the rotate animation:

css
@keyframes rotate {
  from {
    rotate: 0deg;
  }

  to {
    rotate: 360deg;
  }
}

Result

The rendered result looks like this:

Try scrolling the content up. When 50% of the tracked <div> has entered the viewport, the animation will play; when the 50% of the tracked <div> has exited the viewport at either edge, the animation will pause.

Comparing multiple range values

This example is identical to the previous example, except that it allows you to select different activation ranges and then compare their effects.

HTML

The markup is identical to the previous example except that it includes a <select> element that can be used to select different timeline-trigger-activation-range values. When a new value is selected, it is applied to the trigger using JavaScript.

We have hidden the HTML and JavaScript for brevity.

CSS

The CSS is the same as for the previous example, except that this time, we don't set a timeline-trigger-activation-range value on the trigger in CSS, meaning that by default, before a new value is selected via the <select> element, the range will be cover.

css
div.animated {
  animation: rotate 3s infinite linear both;
  animation-trigger: --t play pause;
}

div.trigger {
  timeline-trigger-name: --t;
  timeline-trigger-source: view();
}

Result

The rendered result looks like this:

Try selecting different range values from the <select> dropdown and then for each one scrolling the tracked element up through the viewport to see where the animated element starts and stops rotating. This will give you an idea of each activation range's effect.

Specifications

This feature does not appear to be defined in any specification.

Browser compatibility

See also