Each word tilts up into the headline in its own color, and the dot in front of the line changes to match with a small bump. The extra hues are mixed from your accent, so one variable retints all.
Also known as: rotating words different colors, color cycle text rotator, multicolor changing words.
<div class="txt-color-changing-rotating-words">
<i class="txt-color-changing-rotating-words-dot" aria-hidden="true"></i>Ideas that
<span class="txt-color-changing-rotating-words-words">
<span style="--i: 0">pop.</span>
<span style="--i: 1">glow.</span>
<span style="--i: 2">spark.</span>
</span>
</div>.txt-color-changing-rotating-words {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
--c2: color-mix(in oklch, var(--c) 40%, #ec4899);
--c3: color-mix(in oklch, var(--c) 40%, #f59e0b);
display: flex;
align-items: baseline;
gap: 0.28em;
white-space: nowrap;}
.txt-color-changing-rotating-words-dot {
align-self: center;
width: 0.36em;
height: 0.36em;
margin-right: 0.08em;
border-radius: 50%;
background: var(--c);
animation:
txt-color-changing-rotating-words-tint 6.6s ease-in-out infinite,
txt-color-changing-rotating-words-bump 2.2s ease-out infinite;
}
.txt-color-changing-rotating-words-words {
display: inline-grid;
}
.txt-color-changing-rotating-words-words span {
grid-area: 1 / 1;
justify-self: start;
color: var(--c);
transform-origin: 0 100%;
/* 3 words x 2.2s = 6.6s */
animation: txt-color-changing-rotating-words-tilt 6.6s cubic-bezier(0.3, 0.9, 0.3, 1) infinite;
animation-delay: calc(var(--i) * 2.2s - 7.4s);
}
.txt-color-changing-rotating-words-words span:nth-child(2) { color: var(--c2); }
.txt-color-changing-rotating-words-words span:nth-child(3) { color: var(--c3); }
.txt-color-changing-rotating-words-words span:not(:first-child) {
opacity: 0;
}
@keyframes txt-color-changing-rotating-words-tilt {
0% { opacity: 0; transform: translateY(0.55em) rotate(-8deg); }
8.33% { opacity: 1; transform: translateY(0) rotate(0); }
28.79% {
opacity: 1; transform: translateY(0) rotate(0);
animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0);
}
33.33% { opacity: 0; transform: translateY(-0.5em) rotate(4deg); }
100% { opacity: 0; transform: translateY(0.55em) rotate(-8deg); }
}
/* the dot follows the words: they arrive at 1.4s, 3.6s and 5.8s */
@keyframes txt-color-changing-rotating-words-tint {
0%, 21.21% { background: var(--c); }
27.27%, 54.55% { background: var(--c2); }
60.61%, 87.88% { background: var(--c3); }
93.94%, 100% { background: var(--c); }
}
@keyframes txt-color-changing-rotating-words-bump {
0%, 61.36% { transform: scale(1); }
72.73% { transform: scale(1.5); }
88.64%, 100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
.txt-color-changing-rotating-words, .txt-color-changing-rotating-words *, .txt-color-changing-rotating-words::before, .txt-color-changing-rotating-words::after, .txt-color-changing-rotating-words *::before, .txt-color-changing-rotating-words *::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.