Colors flow through the word letter by letter: your accent, then accent mixed with pink, then with amber, and back. Every color is a color-mix() of the accent, so one variable retints it.
Also known as: color wave text, letter color animation, multicolor text css.
<div class="txt-color-changing-text" aria-label="Good vibes"><span aria-hidden="true"><span style="--i: 0">G</span><span style="--i: 1">o</span><span style="--i: 2">o</span><span style="--i: 3">d</span><span style="--i: 4"> </span><span style="--i: 5">v</span><span style="--i: 6">i</span><span style="--i: 7">b</span><span style="--i: 8">e</span><span style="--i: 9">s</span></span></div>
.txt-color-changing-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;
color: var(--c);}
.txt-color-changing-text span span {
display: inline-block;
animation: txt-color-changing-text-hue 3s linear infinite;
/* minus one period: every letter is already mid-cycle on load */
animation-delay: calc(var(--i) * 0.18s - 3s);
}
@keyframes txt-color-changing-text-hue {
0%, 100% { color: var(--c); }
33% { color: color-mix(in oklch, var(--c) 45%, #ec4899); }
67% { color: color-mix(in oklch, var(--c) 30%, #f59e0b); }
}
@media (prefers-reduced-motion: reduce) {
.txt-color-changing-text, .txt-color-changing-text *, .txt-color-changing-text::before, .txt-color-changing-text::after, .txt-color-changing-text *::before, .txt-color-changing-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.