Start
//

How To: Use CSS Variables

Problem

Create animations that work regardless of timegroup duration. Hard-coding animation delays breaks when durations change.

Solution

Use the CSS variables ef-timegroup sets on itself and its children:

VariableDescription
--ef-durationThis element's duration in seconds (e.g. 5s)
--ef-progressPlayback progress as a number 0–1
--ef-transition-durationDuration of the configured transition
--ef-transition-out-startTime offset when the out-transition begins
--ef-indexZero-based index of this element among its siblings
--ef-stagger-offsetStagger delay for cascading animations
/* Fade-out that always starts 2s before the end */
.my-text {
animation-delay: calc(var(--ef-duration) - 2s);
}
/* Progress bar that grows with playback */
.progress-bar {
width: calc(var(--ef-progress) * 100%);
}
/* Out-transition driven entirely by composition timing */
.scene {
animation: fade-out var(--ef-transition-duration) ease-in-out
var(--ef-transition-out-start) paused;
}

Note: --ef-progress is a number (0–1), not a CSS percentage. Use calc(var(--ef-progress) * 100%) when you need a percentage width or height.

Live

Scaling with Progress