Segments under the headline fill like story progress bars while each word is on screen, and the word changes as its segment completes. One animated @property drives every segment through clamp().
Also known as: stories progress text rotator, headline carousel indicator, timed word slider.
<div class="txt-progress-rotating-words">
<span class="txt-progress-rotating-words-line">Track your
<span class="txt-progress-rotating-words-words">
<span style="--i: 0">habits</span>
<span style="--i: 1">goals</span>
<span style="--i: 2">sleep</span>
<span style="--i: 3">runs</span>
</span>
</span>
<span class="txt-progress-rotating-words-bars" aria-hidden="true">
<i style="--i: 0"></i><i style="--i: 1"></i><i style="--i: 2"></i><i style="--i: 3"></i>
</span>
</div>@property --txt-progress-rotating-words-p {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
.txt-progress-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: inline-flex;
flex-direction: column;
gap: 0.32em;
white-space: nowrap;
/* counts 0 to 4 over the whole cycle, one unit per word */
animation: txt-progress-rotating-words-count 8.8s linear infinite;}
.txt-progress-rotating-words-line {
display: flex;
align-items: baseline;
gap: 0.28em;
}
.txt-progress-rotating-words-words {
display: inline-grid;
color: var(--c);
}
.txt-progress-rotating-words-words span {
grid-area: 1 / 1;
justify-self: start;
/* 4 words x 2.2s = 8.8s, in step with the bars */
animation: txt-progress-rotating-words-swap 8.8s cubic-bezier(0.2, 0.7, 0.2, 1) infinite;
animation-delay: calc(var(--i) * 2.2s - 8.8s);
}
.txt-progress-rotating-words-words span:not(:first-child) {
opacity: 0;
}
.txt-progress-rotating-words-bars {
display: flex;
gap: 0.18em;
}
.txt-progress-rotating-words-bars i {
flex: 1;
height: 0.1em;
border-radius: 0.05em;
background: color-mix(in srgb, var(--c) 22%, transparent);
overflow: hidden;
}
/* segment i shows how far the count has got past i, clamped to 0-1 */
.txt-progress-rotating-words-bars i::after {
content: "";
display: block;
height: 100%;
background: var(--c);
transform-origin: left;
transform: scaleX(clamp(0, var(--txt-progress-rotating-words-p) - var(--i), 1));
}
@keyframes txt-progress-rotating-words-count {
from { --txt-progress-rotating-words-p: 0; }
to { --txt-progress-rotating-words-p: 4; }
}
@keyframes txt-progress-rotating-words-swap {
0% { opacity: 0; transform: translateY(0.35em); }
3.98% { opacity: 1; transform: translateY(0); }
22.16% {
opacity: 1; transform: translateY(0);
animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0);
}
25% { opacity: 0; transform: translateY(-0.35em); }
100% { opacity: 0; transform: translateY(0.35em); }
}
@media (prefers-reduced-motion: reduce) {
.txt-progress-rotating-words, .txt-progress-rotating-words *, .txt-progress-rotating-words::before, .txt-progress-rotating-words::after, .txt-progress-rotating-words *::before, .txt-progress-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.