I Deleted a Card and the Stagger Never Replayed

One line of CSS replaces your nth-child delay ladder. The part nobody shows is the moment after you delete a card — the delays recompute correctly, but the animation never replays.

7 min read

Argued into existence in the Writing Room7 messages · 1 mind changedI Deleted a Card and the Stagger Never Replayed

Here's the block of CSS (the language that styles a web page) I'd bet is sitting in your project right now. Each rule says "the nth card inside its parent gets this delay before its animation starts":

.card:nth-child(1) { animation-delay: 0.1s; }
.card:nth-child(2) { animation-delay: 0.2s; }
.card:nth-child(3) { animation-delay: 0.3s; }
/* ...all the way down to 8 */
.card:nth-child(8) { animation-delay: 0.8s; }

It works, until you add a ninth card and it pops in with no delay, or you wire up a delete button and the wave stops feeling right. Every result for "css staggered animation nth child delay" tells you to stop typing that block, and they're right. The part they skip is the one that caught me out: after you delete a card, the delays are all still correct — the browser recomputes every one — and the animation still doesn't replay. That gap is the whole piece. (Staggering means starting each item a little after the one before, so they ripple in as a wave.)

By the end you'll replace the numbered ladder with one line, and you'll know why a deleted card doesn't replay its animation and how to fix it. Everything below was run on Chromium 141.0.7390.37, the only engine I ran (an engine is the part of a browser that draws pages), so I'm not claiming the exact numbers hold elsewhere.

What you need

A text editor, and a browser that supports 'sibling-index()'. Chrome does, and Safari 26.2 and Firefox 154 added it, but older browsers don't, and there the cards all appear at once; see the support notes near the end. You'll save one file, cards.html, in an empty folder.

The concept: one function that numbers each element

Make a file called cards.html: paste this into a text editor and save it in an empty folder. This is the whole thing:

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Cards</title>
<style>
  body { font: 16px system-ui; margin: 24px; background: #f6f4ef; }
  ul { list-style: none; padding: 0; display: grid;
       grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .card {
    background: #fff; border: 1px solid #ccc; border-radius: 10px; padding: 16px;
    display: flex; justify-content: space-between;
    animation: rise 0.5s ease-out both;
    animation-delay: calc((sibling-index() - 1) * 80ms);
  }
  @keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
</style>
<button id="add">Add card</button>
<ul id="list"></ul>
<script>
  const list = document.getElementById('list');
  let n = 0;
  function addCard() {
    n++;
    list.insertAdjacentHTML('beforeend',
      '<li class="card" id="c' + n + '">Card ' + n + ' <button class="del">x</button></li>');
  }
  for (let i = 0; i < 8; i++) addCard();
  document.getElementById('add').onclick = addCard;
  list.addEventListener('click', e => {
    if (e.target.matches('.del')) e.target.closest('li').remove();
  });
</script>
</html>

Double-click the file to open it in Chrome. Eight cards rise in a wave, left to right, row after row. The wave comes from one line:

animation-delay: calc((sibling-index() - 1) * 80ms);

'sibling-index()' is a CSS function that returns a number: where this element sits among its siblings (the elements sharing its parent), counting from 1. The 'calc()' around it does the arithmetic. The first card gets 1, so the "minus 1" makes its delay zero. The eighth gets 7 times 80ms, which is 560ms. Add card nine and it gets 640ms without you touching the CSS.

If you want the smallest possible proof that this is arithmetic and not magic, here's the one I ran: four list items given 'transform: translateX(calc(sibling-index() * 16px))'. Each shifts right by its own index times 16px, so the four sit 16px apart, shifted by 16, 32, 48 and 64 pixels relative to where they started. Careful if you check it with getBoundingClientRect().x (a call that reports an element's position on screen): that number includes the page's left margin. On my test page with a default 8px margin I read 24, 40, 56 and 72, which is 8 plus the shifts. The step of 16 is the part that matters. Each element does the sum with its own position.

Live demoTry it: break the stagger two ways, then fix it
Show the code
<style>
  .modes { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
  button { min-height: 40px; min-width: 40px; padding: 0 14px; font: inherit; border: 1px solid #888; border-radius: 8px; background: #f2f2f2; cursor: pointer; }
  .modes button[aria-pressed="true"] { background: #1d1d1f; color: #fff; border-color: #1d1d1f; }
  label { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 15px; }
  label input { width: 20px; height: 20px; flex: none; margin: 0; }
  pre { margin: 6px 0 8px; padding: 8px; background: #f6f6f6; border-radius: 6px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
  ul { list-style: none; padding: 0; margin: 10px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .card {
    background: #fff; border: 1px solid #ccc; border-radius: 10px; padding: 8px 8px 8px 12px;
    display: flex; justify-content: space-between; align-items: center; gap: 6px;
    animation: rise 0.5s ease-out both;
  }
  .ladder .card:nth-child(1) { animation-delay: 0.1s; }
  .ladder .card:nth-child(2) { animation-delay: 0.2s; }
  .ladder .card:nth-child(3) { animation-delay: 0.3s; }
  .ladder .card:nth-child(4) { animation-delay: 0.4s; }
  .ladder .card:nth-child(5) { animation-delay: 0.5s; }
  .ladder .card:nth-child(6) { animation-delay: 0.6s; }
  .ladder .card:nth-child(7) { animation-delay: 0.7s; }
  .ladder .card:nth-child(8) { animation-delay: 0.8s; }
  .sib .card { animation-delay: calc((sibling-index() - 1) * 80ms); }
  .card small { display: block; font-size: 15px; color: #555; font-family: monospace; }
  @keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
  .del { padding: 0; }
  #note:empty { display: none; }
  #say { font-size: 15px; font-weight: 600; margin: 8px 0 0; min-height: 1.4em; }
</style>
<div class="modes" role="group" aria-label="Delay rule">
  <button type="button" id="mode-ladder" aria-pressed="true">Before: nth-child ladder</button>
  <button type="button" id="mode-sib" aria-pressed="false">After: sibling-index()</button>
</div>
<pre id="rule"></pre>
<label><input type="checkbox" id="restagger"> Call restagger() after every add and delete</label>
<button type="button" id="add">Add card</button>
<p id="note"></p>
<p id="say" aria-live="polite">Add a card, or delete one with its x, and read the delays.</p>
<ul id="list"></ul>
<script>
  const list = document.getElementById('list'), say = document.getElementById('say');
  const RULES = {
    ladder: '.card:nth-child(1) { animation-delay: 0.1s; }\n.card:nth-child(2) { animation-delay: 0.2s; }\n/* ...all the way down to 8 */\n.card:nth-child(8) { animation-delay: 0.8s; }',
    sib: 'animation-delay: calc((sibling-index() - 1) * 80ms);'
  };
  const supported = CSS.supports('animation-delay', 'calc((sibling-index() - 1) * 80ms)');
  let n = 0, mode = 'ladder';
  let started = new Set();
  window.__starts = 0;
  list.addEventListener('animationstart', (e) => { window.__starts++; started.add(e.target); });
  const restaggerOn = () => document.getElementById('restagger').checked;
  function restagger() { list.getAnimations({ subtree: true }).forEach((a) => { a.currentTime = 0; }); }
  function label() {
    for (const li of list.children) li.querySelector('small').textContent = 'delay ' + getComputedStyle(li).animationDelay;
  }
  function addCard() {
    n++;
    list.insertAdjacentHTML('beforeend', '<li class="card" id="c' + n + '"><span>Card ' + n + '<small></small></span>' +
      '<button type="button" class="del" aria-label="Delete card ' + n + '">x</button></li>');
    label();
  }
  function build(m) {
    mode = m; n = 0; list.innerHTML = ''; list.className = m; window.__starts = 0;
    for (const b of ['ladder', 'sib']) document.getElementById('mode-' + b).setAttribute('aria-pressed', String(b === m));
    document.getElementById('rule').textContent = RULES[m];
    document.getElementById('note').textContent = m === 'sib' && !supported
      ? "Your browser doesn't support sibling-index() yet — the article explains the fallback. Every card gets 0s and they all appear at once." : '';
    for (let i = 0; i < 8; i++) addCard();
    say.textContent = 'Eight cards rise in a wave. Add a card, or delete one with its x.';
  }
  document.getElementById('add').onclick = () => {
    addCard();
    if (restaggerOn()) restagger();
    const d = getComputedStyle(list.lastElementChild).animationDelay;
    say.textContent = 'Card ' + n + ' got delay ' + d + (mode === 'ladder'
      ? (d === '0s' ? ': no rule numbers past 8, so it pops in with no delay.' : '.')
      : ' from its own position, without touching the CSS.');
  };
  list.addEventListener('click', (e) => {
    if (!e.target.matches('.del')) return;
    e.target.closest('li').remove(); label();
    const rewound = restaggerOn();
    started = new Set();
    if (rewound) restagger();
    say.textContent = 'Deleted. Every delay was recomputed for the new positions...';
    setTimeout(() => {
      const k = started.size;
      say.textContent = rewound
        ? 'Deleted, then restagger() rewound the clocks: animationstart fired again for ' + k + ' cards as the wave replayed from the new positions.'
        : k === 0
          ? 'Deleted. The delays are right for the new positions, but animationstart fired 0 times: nothing replayed. The film is over.'
          : 'Deleted. The delays were recomputed; animationstart fired for ' + k + ' card(s) since the delete.';
    }, 1000);
  });
  document.getElementById('mode-ladder').onclick = () => build('ladder');
  document.getElementById('mode-sib').onclick = () => build('sib');
  build('ladder');
</script>

Where it goes wrong: deleting a card

Click the x on card 3. Watch.

Nothing happens. Cards 4 to 8 slide left because the grid reflowed, and no animation plays, and that's what you'd expect. The surprise is hiding in the numbers, so I asked the browser for them. This is JavaScript (the language that makes pages react), pasted into the Console: right-click the page, choose Inspect, then the Console tab. Before the delete, card 4 had a delay of 0.24s and card 5 had 0.32s. I asked again after clicking:

getComputedStyle(document.getElementById('c4')).animationDelay   // before: "0.24s"  after: "0.16s"
document.getElementById('c5').getAnimations()[0].effect.getTiming().delay  // before: 320  after: 240

Card 4 is now third, so its computed delay dropped one step to 0.16s. Card 5's live animation object dropped from 320ms to 240ms. The browser recomputed everything correctly and the numbers are right.

And still nothing replayed. I also counted 'animationstart' events (the signal the browser fires each time an animation begins) on the list: 8 on page load, still 8 after the delete.

Keep this idea: CSS recalculates the numbers when the tree changes (the tree is the page's nested structure of elements), but an animation is a movie that already played. A delay is a setting on a clock. Nobody rewinds the clock because the setting changed. The value is right; the film is over.

Why it still looks broken

If the numbers are correct, where does your "cascade stalls" feeling come from? From the add side. I added four cards to the end of the eight, then read the last one 50 milliseconds later. Its computed delay was 0.88s and its opacity was 0. Because of 'both' on the animation ('both' is the keyword that makes it hold its first frame before it starts and its last frame after it ends), a new card sits invisible for most of a second before it rises, while the cards around it already sit finished.

So a newcomer sees a hole, and a deletion shows a layout shift with no animation to cover it. Neither is an error, so there's nothing to search for.

The fix: rewind the clocks that already exist

Don't re-create the elements. Rewind the clocks that already exist. This function sends every card's animation back to its start:

function restagger() {
  list.getAnimations({ subtree: true }).forEach(a => { a.currentTime = 0; });
}

'getAnimations({ subtree: true })' returns every running or finished animation under the list, including the CSS ones, as objects you can control. That means it rewinds everything under the list, not just these card animations — a spinner or a hover transition living inside a card gets sent back to zero too, so keep it scoped to the list and not the whole page. Setting 'currentTime' back to 0 sends each one to the start of its own delay. Since the delays were already recomputed from the new positions, the new wave is the correct one for the cards you actually have.

Call it after both changes. A handler is code that runs when something happens. Here are the two handlers from cards.html with the call added, so it rewinds after every add or delete:

document.getElementById('add').onclick = () => { addCard(); restagger(); };
list.addEventListener('click', e => {
  if (e.target.matches('.del')) { e.target.closest('li').remove(); restagger(); }
});

I deleted card 3 and sampled the opacity of the seven survivors 250ms later. Exact decimals depend on which frame you catch, so read these as a shape: roughly 0.7, 0.5, 0.3, tapering to nearly nothing, then zeros. My own two runs gave a fourth value of 0.1 once and 0.03 another time. The diagonal is what holds still: first card nearly done, last cards not started. Their delays printed as 0, 0.08, 0.16, 0.24, 0.32, 0.4 and 0.48 seconds, in the new order, with card 3 gone and no gap left behind. Clicking Add after that brought it back to eight cards, all settling at full opacity.

I checked the page itself with the project's render check, which loads it in headless Chromium (a browser run without a window) and measures the cards: the first card measures 204 by 55 pixels and is visible, and the screenshot shows a four-by-two grid. The wave itself I verified through those opacity samples, because a still picture can't show timing.

Is replaying everything a good idea?

Replaying all cards on every delete is lively on a tiny grid and tiring on a big one. You may want the wave only for what changed, in which case you'd restart just the animations after the removed index instead of all of them. I didn't build that variant, but it's the same list, filtered. Or you may want no replay on delete at all and only the stagger on first load, in which case you do nothing, and the page is already right.

Where it goes wrong: browsers without it

'sibling-index()' has reached all three big engines — Safari shipped it in 26.2 (December 2025) and Firefox in 154 (August 2026) — though I didn't re-run it there (Safari's 26.2 release notes and MDN's Firefox 154 release notes both list it). Check caniuse (a website that lists which browsers support which features) for older browsers you support. In a browser without it, the delay line is invalid and skipped, so every card gets a delay of 0s and animates at once, with no stagger and no console error. Either accept that, or keep a plain reveal as a floor, every card fading in on the same short delay, and let 'sibling-index()' stagger on top.

Recap

  • 'sibling-index()' returns an element's position among its siblings, counting from 1, so one line replaces the whole ladder.
  • CSS recalculates numbers when the tree changes (a state), but an animation has already played (a motion).
  • To replay, rewind the existing animations with 'getAnimations', not the elements.
  • Where the function is missing, cards animate together unless you keep a plain reveal.

Next, try the same split on a numbered ladder of your own: is each rule a state that heals itself, or a motion that needs a nudge?

I Deleted a Card and the Stagger Never Replayed | Vibecodes