Words sit on a small deck of cards: the top card flicks away, the one behind it slides forward, and a new card fades in at the back. Each card walks through back, front and exit on one clock.
Also known as: stacked cards text rotator, deck of words animation, flip away card text.
<div class="txt-card-stack-rotating-words">Plan your
<span class="txt-card-stack-rotating-words-deck">
<span style="--i: 0">trip</span>
<span style="--i: 1">week</span>
<span style="--i: 2">launch</span>
<span style="--i: 3">party</span>
</span>
</div>.txt-card-stack-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: center;
gap: 0.3em;
white-space: nowrap;}
.txt-card-stack-rotating-words-deck {
display: inline-grid;
}
.txt-card-stack-rotating-words-deck span {
grid-area: 1 / 1;
padding: 0.04em 0.4em 0.08em;
border-radius: 0.24em;
background: var(--c);
color: #fff;
text-align: center;
transform-origin: 50% 0;
/* 4 cards x 2s = 8s: back, then front, then flicked away */
animation: txt-card-stack-rotating-words-deal 8s cubic-bezier(0.3, 0.7, 0.3, 1) infinite;
animation-delay: calc(var(--i) * 2s - 8s);
}
.txt-card-stack-rotating-words-deck span:first-child {
z-index: 3;
}
.txt-card-stack-rotating-words-deck span:not(:first-child) {
opacity: 0;
}
@keyframes txt-card-stack-rotating-words-deal {
0% { opacity: 1; color: #fff; transform: translate(0, 0) rotate(0) scale(1); z-index: 3; }
18.75% {
opacity: 1; color: #fff; transform: translate(0, 0) rotate(0) scale(1); z-index: 4;
animation-timing-function: cubic-bezier(0.5, 0, 0.8, 0.5);
}
25% { opacity: 0; transform: translate(0.9em, 0.5em) rotate(14deg) scale(1); z-index: 4; }
68.75% { opacity: 0; transform: translate(0, -0.5em) rotate(0) scale(0.76); z-index: 1; }
/* waiting at the back: a lighter card with its word hidden */
75%, 93.75% { opacity: 0.45; color: transparent; transform: translate(0, -0.3em) rotate(0) scale(0.88); z-index: 2; }
100% { opacity: 1; color: #fff; transform: translate(0, 0) rotate(0) scale(1); z-index: 3; }
}
@media (prefers-reduced-motion: reduce) {
.txt-card-stack-rotating-words, .txt-card-stack-rotating-words *, .txt-card-stack-rotating-words::before, .txt-card-stack-rotating-words::after, .txt-card-stack-rotating-words *::before, .txt-card-stack-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.