timeline-trigger-active-range CSS property
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The timeline-trigger-active-range CSS shorthand property specifies a scroll-triggered animation trigger's active range.
Constituent properties
This property is a shorthand for the following CSS properties:
Syntax
/* Keyword */
timeline-trigger-active-range: normal;
timeline-trigger-active-range: auto;
/* Range start value only */
/* Single value */
timeline-trigger-active-range: 0%;
timeline-trigger-active-range: 0px;
timeline-trigger-active-range: cover;
/* Two values */
timeline-trigger-active-range: exit 10%;
timeline-trigger-active-range: contain 50px;
/* Range start and end values */
/* Two values */
timeline-trigger-active-range: 5% 95%;
timeline-trigger-active-range: entry exit;
timeline-trigger-active-range: auto 10%;
timeline-trigger-active-range: 10% normal;
/* Three values */
timeline-trigger-active-range: contain contain 90%;
timeline-trigger-active-range: 200px exit 600px;
timeline-trigger-active-range: entry 10% 90%;
/* Four values */
timeline-trigger-active-range: entry 0% exit 50%;
timeline-trigger-active-range: contain 100px contain 90%;
/* Multiple ranges */
timeline-trigger-active-range:
cover,
entry 0% exit 50%;
/* Global values */
timeline-trigger-active-range: inherit;
timeline-trigger-active-range: initial;
timeline-trigger-active-range: revert;
timeline-trigger-active-range: revert-layer;
timeline-trigger-active-range: unset;
Values
Specified as one or more single animation ranges, separated by commas. Each animation range is specified as a timeline-trigger-active-range-start value, and optionally, a timeline-trigger-active-range-end value.
<'timeline-trigger-active-range-start'>-
The keyword
normal, the keywordauto, a<length-percentage>, a<timeline-range-name>, or a<timeline-range-name><length-percentage>pair, representing thetimeline-trigger-active-range-start. If a<timeline-range-name>is set without a<length-percentage>, the<length-percentage>defaults to0%. <'timeline-trigger-active-range-end'>-
The keyword
normal, the keywordauto, a<length-percentage>, a<timeline-range-name>, or a<timeline-range-name><length-percentage>pair, representing thetimeline-trigger-active-range-end. If a<timeline-range-name>is set without a<length-percentage>, the<length-percentage>defaults to100%.
Percentages are relative to the length of the named timeline range if one is specified, or the timeline represented by normal if not.
Description
The timeline-trigger-active-range property can be used to set a custom active range for a CSS scroll-triggered animation trigger. The active range is the range within which the trigger will stay active it has been activated.
This is useful in situations where you want an animation to be triggered in a small activation range, but then you want the trigger to stay active within a larger range. The trigger will only deactivate when the tracked element leaves the active range.
The ranges can be changed by setting different timeline-trigger-activation-range and timeline-trigger-active-range values.
For example:
.animated {
animation: rotate 3s infinite linear both;
animation-trigger: --my-trigger play pause;
}
.trigger {
timeline-trigger-name: --my-trigger;
timeline-trigger-source: view();
timeline-trigger-activation-range: entry;
timeline-trigger-active-range: cover;
}
Here, we set a timeline-trigger-activation-range value of entry and a timeline-trigger-active-range of cover. This means that the animation will play when the tracked element enters the entry range — the range between which its start edge and end edge scroll into the scrollport. However, once activated, the animation will continue as long as the tracked element stays inside the cover range — it will only pause when the tracked element has completely left the scrollport.
Note:
The active range is designed to be a superset of the activation range — you activate the trigger over a certain range, and it stays active over a larger range. If you set the timeline-trigger-active-range to a smaller range than the timeline-trigger-activation-range, it doesn't invalidate your CSS, but the timeline-trigger-active-range property has no effect.
An animated element can be triggered by the previously-described trigger by referencing the trigger's identifying name in its animation-trigger property.
Note:
The timeline-trigger-active-range property can also be set via the timeline-trigger shorthand property.
Note: It is possible for the animated element and element that creates the trigger to be the same element.
timeline-trigger-active-range value explanation
In terms of explicit and default values, timeline-trigger-active-range works in a very similar way to 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-active-range property, they will be interpreted in the order timeline-trigger-active-range-start then timeline-trigger-active-range-end.
The active range's default value is auto, which sets the active range to the same as the activation range.
A value of normal is equivalent to cover 0% cover 100% for a view progress timeline timeline-trigger-source, and 0% 100% for a scroll progress timeline timeline-trigger-source.
See Explicitly defining both range start and range end with two values for more information.
When defining a timeline-trigger-active-range-start value explicitly and letting the timeline-trigger-active-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. One special case in which timeline-trigger-active-range differs from animation-range is the use of the special auto keyword: When setting timeline-trigger-active-range to normal or auto, the timeline-trigger-active-range-end value is set to auto.
Specifying multiple ranges
When you specify multiple comma-separated values on a single timeline-trigger-active-range property, they are applied to the timeline triggers in the order in which the timeline-trigger-names appear. When the number of triggers and timeline-trigger-active-range property values do not match, they are applied in the same way as multiple animation property values.
For example, if multiple timeline-trigger-name values are set, but only a single timeline-trigger-active-range value is set, the timeline-trigger-active-range will apply to all the timeline-trigger-names. If two timeline-trigger-active-range values are set, they will cycle between the timeline-trigger-names until all of them have a timeline-trigger-active-range value set. And so on.
Consider these declarations:
timeline-trigger-name: --my-trigger, --my-other-trigger, --another-trigger;
timeline-trigger-active-range: cover, contain;
In this case, --my-trigger will use the cover range and --my-other-trigger will use the contain range. As there are three names but only two ranges, the ranges are cycled, so the third trigger name, --another-trigger, will use the cover range.
Formal definition
| Initial value | as each of the properties of the shorthand: |
|---|---|
| Applies to | all elements |
| Inherited | no |
| Percentages | as each of the properties of the shorthand:
|
| Computed value | as each of the properties of the shorthand:
|
| Animation type | Not animatable |
Formal syntax
timeline-trigger-active-range =
[ <'timeline-trigger-active-range-start'> <'timeline-trigger-active-range-end'>? ]#
<timeline-trigger-active-range-start> =
[ auto | normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#
<timeline-trigger-active-range-end> =
[ auto | normal | <length-percentage> | <timeline-range-name> <length-percentage>? ]#
<length-percentage> =
<length> |
<percentage>
Examples
>Active range demonstration
In this example, we demonstrate the effect of defining a timeline-trigger-active-range on a trigger.
HTML
Our markup contains two <div> elements — one to animate and one on which to create a trigger — an <input type="checkbox"> that we will use to toggle the active range on and off, and some basic text content to cause the page to scroll.
We have hidden the text content for brevity.
<div class="animated">I am animated</div>
...
<div class="trigger">I create the trigger</div>
<form>
<label for="active-checkbox">Activate active range?</label>
<input type="checkbox" checked id="active-checkbox" />
</form>
...
CSS
The animated <div> element's position is set to fixed, positioning it near the top-left of the scrollport to enable us to see when its animation starts and stops.
.animated {
position: fixed;
top: 25px;
left: 25px;
}
Next, we define the @keyframes for the rotate animation we will use later:
@keyframes rotate {
from {
rotate: 0deg;
}
to {
rotate: 360deg;
}
}
Using the animation shorthand, the .animated element has the rotate animation applied. Without an associated trigger, the element would start animating when the page loads. The animation-trigger property makes it a triggered animation. The value references a timeline-trigger-name of --t and specifies two <animation-action> values — play and pause — which specify that the animation will play on activation, and pause on deactivation.
.animated {
animation: rotate 3s infinite linear;
animation-trigger: --t play pause;
}
The .trigger <div> element creates the animated <div>'s trigger via the following properties:
- A
timeline-trigger-namewith value--t, which is equal to the identifier referenced in the animated<div>'sanimation-triggerproperty value, associating the two together. - A
timeline-trigger-sourcewith valueview(), 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-rangeofentry— on its own, this means that the trigger will activate when the tracked element starts to enter the scrollport via the scrollport's end edge and deactivate when the tracked element has completely entered the scrollport.
.trigger {
timeline-trigger-name: --t;
timeline-trigger-source: view();
timeline-trigger-activation-range: entry;
}
Now we use a combination of the :has() and :checked pseudo-classes to select the tracked element only when the checkbox is checked. The <form> element appears right after the .trigger <div> as a direct sibling, hence using the + combinator in the selector that we are checking for. The result is that when the checkbox is unchecked, the trigger deactivates as soon as the tracked element leaves the entry range, but when it is checked (as it is by default), the timeline-trigger-active-range property is applied, and the trigger won't deactivate until the tracked element leaves the cover range.
.trigger:has(+ form input:checked) {
timeline-trigger-active-range: cover;
}
Result
Try scrolling the content up. Initially the animation will start when the tracked <div> enters the scrollport end edge, but won't pause until the trigger has completely exited the scrollport again. Note however that when you scroll back down, the animation will not start until the tracked <div> starts to exit the scrollport end edge — it has to reach the activation range (entry) to activate once more.
Now uncheck the checkbox and try scrolling the content up again. Without the active range set, the animation will start when the tracked element starts to enter the scrollport's end edge and then pause as soon as it has completely entered the scrollport. When you scroll it down, the effect happens in reverse — the animation starts when the tracked element starts to exit the scrollport's end edge and then pause as soon as it has completely exited the scrollport.
Specifications
| Specification |
|---|
| Animation Triggers> # propdef-timeline-trigger-active-range> |
Browser compatibility
See also
timeline-trigger-active-range-end,timeline-trigger-active-range-startanimation-triggertimeline-trigger-name,timeline-trigger-source, andtimeline-trigger-activation-rangetimeline-triggershorthand propertytrigger-scope<animation-action>type- Using CSS scroll-triggered animations
- CSS animation triggers module
- CSS animations module