How it works
A reveal that counts its own pieces
Letters that arrive one after another need two things per letter: a starting state to animate from, and a delay that grows with the letter's position. CSS can now supply both. @starting-style describes where an element comes from when it first appears, and sibling-index() tells an element where it stands among its siblings.
1. Splitting without losing the text
To move letters separately, each one needs its own element. Done naively, a screen reader
then meets a heading made of 27 one-letter fragments, which some read letter by letter. So
the component renders the text twice: once whole, visually hidden, for assistive technology;
and once split into pieces inside an aria-hidden wrapper, for the eyes. The
hidden copy is user-select: none, so copying the heading yields the text once. aria-label on the heading would also work for headings, but it is not allowed
on generic elements like <p> or <span>, so the hidden
copy is the one approach that works for every tag.
Characters are split into graphemes with Intl.Segmenter, so "é" written as e
plus a combining accent, or an emoji with a skin tone, stays one piece. Each word is wrapped
in a white-space: nowrap box so lines only break between words; the spaces between words
are ordinary text.
<p class="split" style="--n: 23">
<span class="visually-hidden">Every letter takes its turn</span>
<span aria-hidden="true">
<span class="word" style="--w: 0">
<span class="piece">E</span>
<span class="piece">v</span>
<span class="piece">e</span>
<span class="piece">r</span>
<span class="piece">y</span>
</span>
<span class="word" style="--w: 5">
<span class="piece">l</span>
<span class="piece">e</span>
<span class="piece">t</span>
<span class="piece">t</span>
<span class="piece">e</span>
<span class="piece">r</span>
</span>
…
</span>
</p> 2. The entry: @starting-style
A CSS transition needs a "before" value, and a freshly inserted element has none: it is
simply rendered in its final style. @starting-style supplies one. Its rules apply
only to an element's very first style computation, so each piece starts transparent, shifted and
blurred, and immediately transitions to its normal style. No JavaScript runs for the animation,
and nothing has to be removed afterwards.
Replay works by rendering the pieces anew (a Svelte {#key} block): new elements
get their starting style again.
3. The delay: sibling-index()
sibling-index() is the element's position among its siblings, starting at 1,
and sibling-count() the number of siblings. Both are numbers you can use in calc(): transition-delay: calc((sibling-index() - 1) * 35ms). With
the count, the order can run backwards (n - 1 - i) or out from the middle (|i - (n - 1) / 2|, written as max(x, -x)).
They count element siblings in the DOM, nothing else. For words that is exactly right: every
word is a child of the same wrapper. For characters it is not, because each character is a
child of its word box and the count restarts in every word. The word box therefore carries
its character offset as --w, the character adds its sibling-index(), and the total count comes from the wrapper. Still one custom
property per word instead of one per character.
This is the CSS for your current settings:
.piece {
display: inline-block;
--_i: var(--i, calc(var(--w) + sibling-index() - 1));
--_n: var(--n); /* set on the wrapper: characters are only siblings within a word */
--_step: var(--_i);
transition-property: opacity, translate, rotate, scale, filter;
transition-duration: 700ms;
transition-timing-function: linear(0, 0.025, 0.087, 0.175, 0.277, 0.384, 0.489, 0.589, 0.68, 0.761, 0.83, 0.888, 0.934, 0.971, 0.999, 1.019, 1.033, 1.041, 1.045, 1.046, 1.044, 1.041, 1.037, 1.032, 1.027, 1.023, 1.018, 1.014, 1.01, 1.007, 1.005, 1.003, 1.001, 1, 0.999, 0.998, 0.998, 0.998, 0.998, 0.998, 1);
transition-delay: calc(var(--_step) * 35ms);
}
@media (prefers-reduced-motion: no-preference) {
@starting-style {
.piece {
opacity: 0;
translate: 0 24px;
filter: blur(6px);
}
}
}
@media (prefers-reduced-motion: reduce) {
.piece { transition: opacity 300ms ease-out; }
@starting-style { .piece { opacity: 0; } }
} 4. The fallback: an inline index
Where sibling-index() is unknown, the component writes the index itself, as a --i custom property on every piece. The CSS reads var(--i, calc(sibling-index() - 1)): the inline value when there is one, the
function otherwise. CSS.supports('z-index', 'sibling-index()') answers
reliably, because browsers that don't know the function reject the value. Before that check
has run (on the prerendered page) the inline index is always written, so the first reveal is
staggered everywhere. Set Index source to compare both; the result is identical.
Forcing sibling-index in a browser without it leaves the declaration invalid, and the delay
falls back to 0: everything arrives at once.
The list subject uses Stagger, which applies the same rules to whatever
children you give it. Its fallback writes --i and --n onto the children
from script, right after they are inserted and before the browser styles them.
Motion and accessibility
- Under
prefers-reduced-motion: reducethe pieces only fade in, all together, in 300 ms. No movement, blur or stagger. - The reveal is a single transition that ends on its own, here after 1470 ms. It is not paused by the Pause animations regions on other pages, which pause CSS animations, not transitions. Keep long texts short on stagger: content that moves for more than five seconds needs a way to stop it (WCAG 2.2.2).
- Screen readers get the whole text once, from the hidden copy; the pieces are
aria-hidden. The text is real text before, during and after the reveal. - Splitting into inline-blocks disables kerning and ligatures across pieces, and can break scripts whose letters join (Arabic, Devanagari). Use word mode for those.
Browser support
sibling-index() and sibling-count() are Baseline newly available
since 2026-08-18 (Chrome 138, Firefox 154, Safari 26.2) and @starting-style since 2024-08-06, per web-features 3.44.0. The linear() easing behind the
spring is Baseline widely available. Without sibling-index() the inline index
takes over; without @starting-style the text simply appears, with no reveal. Tested
in Chromium 156 only; Firefox and Safari are untested.
Performance notes
- Opacity and transforms are cheap; blur is not. Each blurred piece is a separate filter while it sharpens. For long paragraphs in character mode, set Blur to 0 (judgment).
- Every character is an element. A few hundred are fine; split whole articles by word, or not at all.
- Once the reveal has finished, nothing runs: the pieces are static inline boxes.