Stagger & Complex Sequences — Web Animation

Stagger = several elements run the same animation, but start in turn, a fixed gap apart. The delay of element i = the starting delay (the wait before the…

In the Saman dance, every dancer makes the same movement, but the wave travels from one end of the row to the other, each dancer a little after the one before. In animation, this wave is called a stagger: several elements run the same animation, but take turns starting, a fixed gap apart. The dancers are the elements, and the time between two dancers is the gap. The next verse only begins once the wave is over. This order is called a sequence: the next animation only starts once the previous one has finished. On Mrs. Sri's page, three room cards enter 60 ms apart, then the toast appears once the last card has landed.

Calculating stagger timing

Take a guess first: the Terrace Room, the Attic Room and the Garden Room each enter in 300 ms, 60 ms apart. When does the Garden Room start moving, and when does the whole sequence finish?

The delay of card i (counted from 0) = the starting delay + i × the gap. The starting delay is the wait before the first card starts, here 0. Each card's finish time = its delay + the duration:

Card i Starts Finishes
Terrace Room 0 0 ms 300 ms
Attic Room 1 60 ms 360 ms
Garden Room 2 120 ms 420 ms

So the Garden Room starts at 120 ms, and the sequence finishes at 420 ms = 2 × 60 + 300. The general formula: total = starting delay + (count - 1) × gap + duration.

The order does not have to run from the front. The from option decides which element starts first. What changes is only each element's "distance": how many steps it is from the starting point. In the code below, this distance is called steps:

from Distance of element i 5 elements, starting delay 200, gap 50
"start" i 200, 250, 300, 350, 400
"end" (count - 1) - i 400, 350, 300, 250, 200
"center" Math.abs(i - (count - 1) / 2) 300, 250, 200, 250, 300

With "center", the middle element (distance 0) starts first. The function createStagger calculates the delay for all three from values:

function createStagger(items, options) {
  const { delay, staggerAmount, from } = options;
  const last = items.length - 1;
  return items.map((item, i) => {
    let steps = i;                                        // "start": the usual order
    if (from === 'end') steps = last - i;                 // the last one goes first
    if (from === 'center') steps = Math.abs(i - last / 2); // the middle one goes first
    return { item, delay: delay + steps * staggerAmount };
  });
}

Motion uses the same formula: stagger(0.06, { from: 'center' }) = startDelay + 0.06 × |origin - i| seconds, where origin is the starting point. The |...| sign means the absolute value, the same as Math.abs. GSAP uses this formula too: stagger: 0.15 means the 5th element (index 4) starts at 4 × 0.15 = 0.6 seconds. In Motion 12, staggerChildren in the parent's transition still works but is marked deprecated. Its replacement is delayChildren: stagger(0.06) (the Framer Motion Basics lesson).

Stagger with CSS: --i and calc()

CSS does not know an element's position among the other elements. So we write the position ourselves in the HTML, through a custom property (a CSS variable you make yourself, with a name that starts with --):

<ul class="rooms">
  <li class="room" style="--i: 0">Terrace Room</li>
  <li class="room" style="--i: 1">Attic Room</li>
  <li class="room" style="--i: 2">Garden Room</li>
</ul>

Then the CSS uses --i to calculate each card's delay:

.room {
  animation: enter 300ms ease-out both;        /* both: hidden while it waits out the delay */
  animation-delay: calc(var(--i) * 60ms);      /* 0, 60, 120 ms */
}
@keyframes enter { from { opacity: 0; translate: 0 16px; } }

sibling-index(): the position without --i

CSS Values 5 (a newer CSS specification) adds two functions. sibling-index() gives an element's position among its siblings (the other elements with the same parent). sibling-count() gives the number of children in its parent, the element itself included. sibling-index() starts at 1, not 0. The first line below is a fallback (a backup for browsers without support):

.room { animation-delay: calc(var(--i, 0) * 60ms); }              /* fallback */
.room { animation-delay: calc((sibling-index() - 1) * 60ms); }    /* 0, 60, 120 ms */

Support: Chrome 138 (24 June 2025), Safari 26.2 (12 December 2025) and Firefox 154 (18 August 2026). We checked with getAnimations(): Chromium 147 and WebKit 26.4 give delays of 0, 60, 120 ms. Firefox 146 does not know sibling-index() yet, so it drops the second line when it reads the CSS, and the fallback line applies. Without a fallback line, every card in Firefox 146 gets a 0 ms delay. Without the - 1, the Terrace Room waits 60 ms too.

One more thing we found: keep var() out of the sibling-index() line. A declaration (one line of a property and its value) containing var() is not checked when the CSS is read, so it is not dropped, and the fallback line loses. In Firefox 146 that line only fails later, and the delay becomes 0, not the fallback value.

Stagger with the Web Animations API

In JavaScript the delay is the ordinary delay option:

const cards = document.querySelectorAll('.room');
const anims = [...cards].map((card, i) =>
  card.animate(
    [{ opacity: 0, transform: 'translateY(16px)' }, { opacity: 1, transform: 'none' }],
    { duration: 300, delay: i * 60, easing: 'ease-out', fill: 'backwards' }, // backwards = hidden during the delay
  ),
);

fill: 'backwards' does the job of both in CSS.

Sequences with promises: await animation.finished

Every Animation object has finished, a Promise that settles when the animation ends. With await, the next step waits for that Promise first. In this code, enterCards() is the stagger code above, wrapped in a function that returns anims:

async function showRooms() {
  const anims = enterCards();                             // three cards, 60 ms stagger
  await Promise.all(anims.map((a) => a.finished));        // wait for the last one: 420 ms
  await toast.animate(
    [{ opacity: 0, transform: 'translateY(8px)' }, { opacity: 1, transform: 'none' }],
    { duration: 200, easing: 'ease-out' },
  ).finished;                                             // the toast: 420 to 620 ms
}

How much stagger is too much

The first generation of Material Design (the version before Material 3, at m1.material.io, the Choreography page) says: "Do not wait for each item to fully animate before introducing the next item." and "Begin each item's staggered entrance no more than 20ms apart." Nielsen Norman Group puts most UI animations at 100 to 500 ms, and Apple advises "Let people cancel motion". Both mean: do not make people wait.

This lesson uses 60 ms on purpose, more than those 20 ms. What matters is the total time: three cards with a 60 ms gap finish at 420 ms, under 500 ms, and the wave is still easy to see. Calculate the total before you pick a gap. Twelve search results with a 60 ms gap: the last card only starts at 660 ms and finishes at 960 ms, almost twice 500 ms. Limit the total gap. This code uses a 60 ms gap, but all the gaps together are 200 ms at most:

const each = Math.min(60, 200 / (cards.length - 1)); // 12 cards: 18.2 ms; done at 500 ms

GSAP has an option for exactly this: stagger: { amount: 0.2 } spreads 0.2 seconds across all the elements. When "Reduce motion" is on, drop the travel and the stagger: every card fades in 150 ms together.

⚠️ Stagger sums that often go wrong

TL;DR: Stagger = several elements run the same animation, but start in turn, a fixed gap apart. The delay of element i = the starting delay (the wait before the first one) + distance × gap. The distance is how many steps the element is from the one that starts first; with the from option it is i ("start"), (count - 1) - i ("end"), or Math.abs(i - (count - 1) / 2) ("center"). Three 300 ms cards 60 ms apart: the Garden Room starts at 120 ms, all done at 420 ms. CSS: animation-delay: calc(var(--i) * 60ms) with both (it hides the card during its delay). sibling-index() (an element's position in its parent) starts at 1 (calc((sibling-index() - 1) * 60ms)), in Chrome 138, Safari 26.2 and Firefox 154, with a --i fallback line. WAAPI (the Web Animations API): delay: i * 60 with fill: 'backwards'. Sequence = the next animation waits for the previous one to finish: await Promise.all(anims.map((a) => a.finished)) then the toast (420 to 620 ms). finished rejects when the animation is cancelled. GSAP stagger: 0.15: the 5th element starts at 0.6 seconds; Motion 12: delayChildren: stagger(0.06) replaces staggerChildren. Do not let the sequence drag: first-generation Material says no more than 20 ms apart, NN/g 100 to 500 ms. 12 cards with a 60 ms gap finish at 960 ms, so limit the total gap (Math.min(60, 200 / (n - 1)), n = the number of cards, or GSAP amount).

⚡ Stagger and sequence

Meaning: A stagger: several elements run the same animation, but take turns to start, a fixed gap apart. A sequence: the next animation only starts once the previous one has finished. On Mrs. Sri's page, three room cards enter in turn (a stagger), then the toast appears once the last card has finished (a sequence).

⚡ Calculating the timing

Guess first: the Terrace, Attic and Garden Rooms each enter in 300 ms, one every 60 ms. When does the Garden Room start, and when is everything done?

The Garden Room starts at 120 ms, and everything is done at 420 ms = 2 × 60 + 300.

Meaning: The delay of card i (counted from 0) = the starting delay + i × the gap. The starting delay is the wait before the first card, here 0. The total = the starting delay + (count - 1) × gap + duration.

⚡ Stagger with CSS

Write:

.room {
  animation: enter 300ms ease-out both;        /* both: hidden while it waits out the delay */
  animation-delay: calc(var(--i) * 60ms);      /* 0, 60, 120 ms */
}
@keyframes enter { from { opacity: 0; translate: 0 16px; } }

Meaning: CSS doesn't know an element's position. So the position is written in the HTML as a custom property (a CSS variable), for example style="--i: 2", then calc() turns it into time: 2 × 60 = 120 ms. both hides the card during its delay. Without both, the card shows in full during its delay, then flashes away.

⚡ Don't make people wait

Meaning: Twelve cards that enter in 300 ms with a 60 ms gap only finish at 960 ms, almost twice 500 ms, the limit for a UI animation that still feels right. Limit the total gap, for example Math.min(60, 200 / (cards.length - 1)) (cards = the list of cards): the gap is 60 ms, but all the gaps together are 200 ms at most. When "Reduce motion" is on, every card fades in 150 ms together.

What you will learn