Each new word fades in and a highlighter stroke sweeps under it from the left, slightly skewed like a real marker. The word stays in the text color; only the tinted stroke uses the accent.
Also known as: marker highlight word swap, highlighted rotating text, highlighter pen text animation.
<div class="txt-highlighter-rotating-words">Study
<span class="txt-highlighter-rotating-words-words">
<span style="--i: 0">smarter</span>
<span style="--i: 1">faster</span>
<span style="--i: 2">together</span>
</span>
</div>.txt-highlighter-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;
display: flex;
align-items: baseline;
gap: 0.28em;
white-space: nowrap;}
.txt-highlighter-rotating-words-words {
display: inline-grid;
}
.txt-highlighter-rotating-words-words span {
grid-area: 1 / 1;
justify-self: start;
position: relative;
/* 3 words x 2.4s = 7.2s */
animation: txt-highlighter-rotating-words-word 7.2s cubic-bezier(0.2, 0.7, 0.2, 1) infinite;
animation-delay: calc(var(--i) * 2.4s - 8.1s);
}
.txt-highlighter-rotating-words-words span:not(:first-child) {
opacity: 0;
}
/* the marker stroke, behind the letters */
.txt-highlighter-rotating-words-words span::before {
content: "";
position: absolute;
z-index: -1;
top: 0.42em;
bottom: 0.04em;
left: -0.1em;
right: -0.1em;
border-radius: 0.08em 0.3em 0.12em 0.25em;
background: color-mix(in srgb, var(--c) 38%, transparent);
transform: skewX(-14deg) rotate(-1.5deg) scaleX(0);
transform-origin: left;
animation: txt-highlighter-rotating-words-mark 7.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
animation-delay: inherit;
}
@keyframes txt-highlighter-rotating-words-word {
0% { opacity: 0; transform: translateY(0.15em); }
4.17% { opacity: 1; transform: translateY(0); }
29.17% {
opacity: 1; transform: translateY(0);
animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0);
}
33.33% { opacity: 0; transform: translateY(0.12em); }
100% { opacity: 0; transform: translateY(0.15em); }
}
@keyframes txt-highlighter-rotating-words-mark {
0%, 4.17% { transform: skewX(-14deg) rotate(-1.5deg) scaleX(0); }
11.11%, 100% { transform: skewX(-14deg) rotate(-1.5deg) scaleX(1); }
}
@media (prefers-reduced-motion: reduce) {
.txt-highlighter-rotating-words, .txt-highlighter-rotating-words *, .txt-highlighter-rotating-words::before, .txt-highlighter-rotating-words::after, .txt-highlighter-rotating-words *::before, .txt-highlighter-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.