All the letters appear stacked on one spot in the middle, then fan out to their places like a deck of cards. Each offset is worked out in calc() from the letter's index and the count.
Also known as: text expand from center, fan out text animation, letters fly out from middle.
<div class="txt-letters-spread-from-center" aria-label="Fan favorite"><span style="--i: 0">F</span><span style="--i: 1">a</span><span style="--i: 2">n</span><span style="--i: 3"> </span><span style="--i: 4">f</span><span style="--i: 5">a</span><span style="--i: 6">v</span><span style="--i: 7">o</span><span style="--i: 8">r</span><span style="--i: 9">i</span><span style="--i: 10">t</span><span style="--i: 11">e</span></div>
.txt-letters-spread-from-center {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
/* --n = number of letters */
--n: 12;
color: var(--c);
white-space: nowrap;}
.txt-letters-spread-from-center span {
/* how many letter widths this letter sits from the middle */
--o: calc((var(--n) - 1) / 2 - var(--i));
display: inline-block;
animation: txt-letters-spread-from-center-fan 1.4s both;
}
@keyframes txt-letters-spread-from-center-fan {
0% {
opacity: 0;
transform: translateX(calc(var(--o) * 0.55em)) rotate(calc(var(--o) * 5deg)) scale(0.6);
animation-timing-function: ease-out;
}
22% {
opacity: 1;
transform: translateX(calc(var(--o) * 0.55em)) rotate(calc(var(--o) * 5deg)) scale(1);
animation-timing-function: cubic-bezier(0.3, 0.9, 0.3, 1);
}
100% { opacity: 1; transform: translateX(0) rotate(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
.txt-letters-spread-from-center, .txt-letters-spread-from-center *, .txt-letters-spread-from-center::before, .txt-letters-spread-from-center::after, .txt-letters-spread-from-center *::before, .txt-letters-spread-from-center *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.