A solid bar in the accent color sweeps over the word, the word changes while it is hidden, and the bar pulls away to the right. Editorial and punchy; the bar flips its transform-origin mid-sweep.
Also known as: color block text swap, swipe reveal word rotator, bar reveal words.
<div class="txt-block-reveal-rotating-text">Stories that
<span class="txt-block-reveal-rotating-text-words">
<span style="--i: 0">move</span>
<span style="--i: 1">sell</span>
<span style="--i: 2">stick</span>
<i class="txt-block-reveal-rotating-text-block" aria-hidden="true"></i>
</span>
</div>.txt-block-reveal-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-block-reveal-rotating-text-words {
position: relative;
display: inline-grid;
color: var(--c);
}
.txt-block-reveal-rotating-text-words span {
grid-area: 1 / 1;
/* each word shows for one 2.2s slot, switching while the bar covers it */
animation: txt-block-reveal-rotating-text-show 6.6s infinite;
animation-delay: calc(var(--i) * 2.2s - 7s);
}
.txt-block-reveal-rotating-text-words span:not(:first-child) {
opacity: 0;
}
.txt-block-reveal-rotating-text-block {
position: absolute;
inset: 0.04em -0.08em;
background: var(--c);
transform: scaleX(0);
animation: txt-block-reveal-rotating-text-sweep 2.2s cubic-bezier(0.7, 0, 0.3, 1) infinite;
}
@keyframes txt-block-reveal-rotating-text-show {
0%, 33.33% { opacity: 1; }
33.34%, 100% { opacity: 0; }
}
@keyframes txt-block-reveal-rotating-text-sweep {
0%, 63.64% { transform: scaleX(0); transform-origin: left; }
81.82% { transform: scaleX(1); transform-origin: left; }
81.86% { transform: scaleX(1); transform-origin: right; }
100% { transform: scaleX(0); transform-origin: right; }
}
@media (prefers-reduced-motion: reduce) {
.txt-block-reveal-rotating-text, .txt-block-reveal-rotating-text *, .txt-block-reveal-rotating-text::before, .txt-block-reveal-rotating-text::after, .txt-block-reveal-rotating-text *::before, .txt-block-reveal-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.