Letter by letter, the word drifts up, swells and blurs away like smoke while the next word condenses out of a haze. Each letter carries its index and each word its slot, so one keyframe runs them all.
Also known as: smoke text effect css, evaporating text animation, dissolving word swap.
<div class="txt-smoke-rotating-text" aria-label="Clear your mind, inbox, desk">Clear your
<span class="txt-smoke-rotating-text-words" aria-hidden="true">
<span style="--w: 0"><span style="--i: 0">m</span><span style="--i: 1">i</span><span style="--i: 2">n</span><span style="--i: 3">d</span></span>
<span style="--w: 1"><span style="--i: 0">i</span><span style="--i: 1">n</span><span style="--i: 2">b</span><span style="--i: 3">o</span><span style="--i: 4">x</span></span>
<span style="--w: 2"><span style="--i: 0">d</span><span style="--i: 1">e</span><span style="--i: 2">s</span><span style="--i: 3">k</span></span>
</span>
</div>.txt-smoke-rotating-text {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
display: flex;
align-items: baseline;
gap: 0.28em;
white-space: nowrap;}
.txt-smoke-rotating-text-words {
display: inline-grid;
color: var(--c);
}
.txt-smoke-rotating-text-words > span {
grid-area: 1 / 1;
display: flex;
}
.txt-smoke-rotating-text-words span span {
display: inline-block;
/* 3 words x 2.4s = 7.2s, plus 60ms per letter */
animation: txt-smoke-rotating-text-drift 7.2s cubic-bezier(0.3, 0.6, 0.4, 1) infinite;
animation-delay: calc(var(--i) * 60ms + var(--w) * 2.4s - 8s);
}
.txt-smoke-rotating-text-words > span:not(:first-child) span {
opacity: 0;
}
@keyframes txt-smoke-rotating-text-drift {
0% { opacity: 0; transform: translate(0, 0.2em) rotate(0) scale(1); filter: blur(0.12em); }
8.33% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); filter: blur(0); }
22.22% {
opacity: 1; transform: translate(0, 0) rotate(0) scale(1); filter: blur(0);
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
}
27.78% {
opacity: 0.55; transform: translate(0.12em, -0.35em) rotate(calc(var(--i) * 4deg - 6deg)) scale(1.15);
filter: blur(0.08em);
}
33.33% {
opacity: 0; transform: translate(0.3em, -0.9em) rotate(calc(var(--i) * 9deg - 14deg)) scale(1.5);
filter: blur(0.25em);
}
100% { opacity: 0; transform: translate(0, 0.2em) rotate(0) scale(1); filter: blur(0.12em); }
}
@media (prefers-reduced-motion: reduce) {
.txt-smoke-rotating-text, .txt-smoke-rotating-text *, .txt-smoke-rotating-text::before, .txt-smoke-rotating-text::after, .txt-smoke-rotating-text *::before, .txt-smoke-rotating-text *::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.