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 the start and end of a scroll-triggered animation trigger's activation range.
Constituent properties
This property is a shorthand for the following CSS properties:
Syntax
/* Keyword */
timeline-trigger-activation-range: normal;
/* Range start only */
/* Offset only */
timeline-trigger-activation-range: 40%;
timeline-trigger-activation-range: 200px;
/* Named timeline only */
timeline-trigger-activation-range: contain;
timeline-trigger-activation-range: entry;
/* Named timeline and offset value */
timeline-trigger-activation-range: exit 50%;
timeline-trigger-activation-range: contain 150px;
/* Range start and end */
timeline-trigger-activation-range: 20% 80%;
timeline-trigger-activation-range: entry exit;
timeline-trigger-activation-range: normal 20%;
timeline-trigger-activation-range: 20% normal;
/* Offset on start only */
timeline-trigger-activation-range: entry 10% 90%;
/* Offset on end only */
timeline-trigger-activation-range: 200px exit 300px;
/* Named timeline and offset for both start and end */
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;
Values
This property is specified as a comma-separated list of animation ranges. Each animation range is specified as a timeline-trigger-activation-range-start value and, optionally, a timeline-trigger-activation-range-end value.
<'timeline-trigger-activation-range-start'>-
The keyword
normal, a<length-percentage>, a<timeline-range-name>, or a<timeline-range-name>followed by a<length-percentage>, representing thetimeline-trigger-activation-range-start. If a<timeline-range-name>is set without a<length-percentage>, the<length-percentage>defaults to0%. <'timeline-trigger-activation-range-end'>-
The keyword
normal, a<length-percentage>, a<timeline-range-name>, or a<timeline-range-name>followed by a<length-percentage>, representing thetimeline-trigger-activation-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-activation-range property can be used to explicitly specify the start or start and end of a trigger's activation range. The property sets both the timeline-trigger-activation-range-start and timeline-trigger-activation-range-end properties in one declaration, with each specified as a timeline range, offset, or both. Start and end offsets are both measured from the start of their ranges. If only the timeline-trigger-activation-range-start value is specified, the timeline-trigger-activation-range-end value defaults to normal, which is either contain 100% or scroll 100%, depending on the timeline-trigger-source value.
A trigger's activation range is the range along the associated scrollport within which a CSS scroll-triggered animation trigger will activate. Activation occurs when the tracked element enters the activation range, and deactivation occurs when it leaves the active range.
The default value is normal, which sets the activation range to the default named range. The default named range depends on the timeline-trigger-source: it is equivalent to cover for a view progress timeline and scroll for a scroll progress timeline. The default offset values are 0% for activation start and 100% for activation end. Therefore, normal resolves to either cover 0% cover 100% or scroll 0% scroll 100%.
Other timeline-trigger-activation-range values can be used to set:
- Start and end offsets from the
normalrange -
A
<length>or<percentage>value specifies an offset from the beginning of thenormaltimeline, which again defaults tocoverfor aview()progress timeline source, andscrollfor ascroll()progress timeline source. Negative values outset the start and end, resulting in a longer activation range. Positive values inset the start and end of the activation range, shortening it. - Specific named ranges
-
If a
<timeline-range-name>values is set without including an offset, the offset defaults to0%for start and100%for end values. The named timeline ranges includecover,contain,entry,exit,entry-crossing,exit-crossing, andscroll. See Understanding timeline range names. - Offsets from specific named ranges
-
When both a
<timeline-range-name>and<length>or<percentage>value are specified for the start or end, the value is specified as a length or percentage offset from the start of the named range. Percentage values are relative to the full length of the named range specified. See Setting insets using percentages.
In each component of a timeline-trigger-activation-range value, the <timeline-range-name> value must come before the <length> or <percentage> offset. In the following example, you might think timeline-trigger-activation-range-start is set to contain and timeline-trigger-activation-range-end is set to 50%, but that is not the case. Instead, timeline-trigger-activation-range-start is set to contain 50% while timeline-trigger-activation-range-end defaults to normal:
timeline-trigger-activation-range: contain 50%;
To set timeline-trigger-activation-range-start to contain and timeline-trigger-activation-range-end to 50%, explicitly set 0%, which is the default start offset:
timeline-trigger-activation-range: contain 0% 50%;
By default, the active range is the same as the activation range. To make the active range longer than the activation range, use the timeline-trigger-active-range-start and timeline-trigger-active-range-end properties, or the timeline-trigger-active-range shorthand. Making the active range longer than the activation range is useful when you want to trigger an animation in a small activation range but keep the trigger active over a larger range.
The timeline-trigger-activation-range property, along with the timeline-trigger-name, timeline-trigger-source, and timeline-trigger-active-range properties, can also be set using the timeline-trigger shorthand.
Explicit and default values for timeline-trigger-activation-range
In terms of explicit and default values, timeline-trigger-activation-range works in exactly the same way as the animation-range property. See the following for more information:
Specifying multiple ranges
When multiple values are specified in a comma-separated timeline-trigger-activation-range declaration, each value applies to a timeline trigger in the order in which the names appear in the timeline-trigger-name property. When the number of triggers and timeline-trigger-activation-range property values do not match, they are applied in the same way as multiple animation property values:
- If the number of
timeline-trigger-activation-rangevalues exceeds the number oftimeline-trigger-namevalues, the excess range values are discarded. - If the number of trigger names is greater than the number of ranges, the
timeline-trigger-activation-rangevalues are cycled until everytimeline-trigger-namevalue has atimeline-trigger-activation-rangevalue set. - If multiple
timeline-trigger-namevalues are set, but only onetimeline-trigger-activation-rangevalue is set, thetimeline-trigger-activation-rangewill apply to all thetimeline-trigger-names.
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-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 inset a scroll-triggered animation trigger's activation range by setting a custom timeline-trigger-activation-range value.
HTML
Our markup contains two <div> elements—one to animate and one to create a trigger on—and some text content to make the page scroll. We have hidden the text content for brevity.
<div class="animated">I am animated</div>
...
<div class="trigger">I create the trigger</div>
...
CSS
The .animated element's position is set to fixed, positioning it near the top-left of the scrollport so we can see when its animation starts and stops.
.animated {
position: fixed;
top: 25px;
left: 25px;
}
Next, we define the @keyframes for a rotate animation:
@keyframes rotate {
from {
rotate: 0deg;
}
to {
rotate: 360deg;
}
}
Using the animation shorthand, the rotate animation is applied to the .animated element. 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 plays on activation and pauses on deactivation.
.animated {
animation: rotate 3s infinite linear;
animation-trigger: --t play pause;
}
The .trigger element creates the .animated element's trigger via the following properties:
- A
timeline-trigger-namewith value--t, which is equal to the identifier referenced in the.animatedelement'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 50% exit 50%. Theentryrange spans from when the trigger element first starts entering the scrollport to when it has completely entered the scrollport, while theexitrange spans from when the trigger element first starts leaving the scrollport to when it has completely left the scrollport. This value sets the trigger's activation range to start at50%through theentryrange and end50%through theexitrange.
.trigger {
timeline-trigger-name: --t;
timeline-trigger-source: view();
timeline-trigger-activation-range: entry 50% exit 50%;
}
Result
Try scrolling the content up and down. The animation starts playing when 50% of the tracked .trigger element has entered the scrollport in either direction and pauses when 50% of the trigger element has exited the scrollport at either edge.
Comparing multiple range values
This example is identical to the previous example, except that it allows selecting different activation ranges to compare their effects.
The markup is the same as the previous example except we've added a <select> element that can be used to change the timeline-trigger-activation-range value. When a new value is selected, it is applied to the trigger element using JavaScript. We have hidden the HTML and JavaScript for brevity.
CSS
The CSS is the same as for the previous example, except we've omitted the timeline-trigger-activation-range value. This means that until a range value is selected, the range will default to normal, which is cover 0% cover 100% in this case.
.animated {
animation: rotate 3s infinite linear;
animation-trigger: --t play pause;
}
.trigger {
timeline-trigger-name: --t;
timeline-trigger-source: view();
}
Result
Select different range values then scroll the tracked element up and down the scrollport to see where the animated element starts and stops rotating.
Specifications
| Specification |
|---|
| Animation Triggers> # propdef-timeline-trigger-activation-range> |
Browser compatibility
See also
animation-triggertimeline-trigger-name,timeline-trigger-source, andtimeline-trigger-active-rangetimeline-triggershorthand propertytrigger-scope<animation-action>type- Using CSS scroll-triggered animations
- CSS animation triggers module
- CSS animations module