A slot machine reel spins through the options with a touch of motion blur and lands on the next word with a small bounce. The reel is one long repeating list, so every spin moves the same distance.
Also known as: slot machine text animation, spinning reel words, random word picker animation.
<div class="txt-slot-machine-rotating-words" aria-label="Lunch is tacos, sushi, ramen or pizza">Lunch is
<span class="txt-slot-machine-rotating-words-reel" aria-hidden="true">
<span class="txt-slot-machine-rotating-words-strip"><span>tacos</span><span>sushi</span><span>ramen</span><span>pizza</span><span>tacos</span><span>sushi</span><span>ramen</span><span>pizza</span><span>tacos</span><span>sushi</span><span>ramen</span><span>pizza</span><span>tacos</span><span>sushi</span><span>ramen</span><span>pizza</span><span>tacos</span><span>sushi</span><span>ramen</span><span>pizza</span><span>tacos</span></span>
</span>
</div>.txt-slot-machine-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-slot-machine-rotating-words-reel {
position: relative;
display: block;
height: 1.2em;
padding: 0 0.3em;
overflow: hidden;
border-radius: 0.2em;
background: color-mix(in srgb, var(--c) 12%, transparent);
color: var(--c);
}
/* shading at the top and bottom sells the curve of the drum */
.txt-slot-machine-rotating-words-reel::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(color-mix(in srgb, var(--c) 35%, transparent), transparent 32%, transparent 68%, color-mix(in srgb, var(--c) 35%, transparent));
}
.txt-slot-machine-rotating-words-strip {
display: flex;
flex-direction: column;
text-align: center;
/* 21 rows: every spin travels 5 rows and lands on the next word */
animation:
txt-slot-machine-rotating-words-spin 8.8s cubic-bezier(0.5, 0, 0.15, 1.04) infinite,
txt-slot-machine-rotating-words-blur 2.2s linear infinite;
}
.txt-slot-machine-rotating-words-strip span {
height: 1.2em;
}
@keyframes txt-slot-machine-rotating-words-spin {
0%, 13.64% { transform: translateY(0); }
25%, 38.64% { transform: translateY(-6em); }
50%, 63.64% { transform: translateY(-12em); }
75%, 88.64% { transform: translateY(-18em); }
100% { transform: translateY(-24em); }
}
@keyframes txt-slot-machine-rotating-words-blur {
0%, 56% { filter: blur(0); }
72% { filter: blur(0.06em); }
92%, 100% { filter: blur(0); }
}
@media (prefers-reduced-motion: reduce) {
.txt-slot-machine-rotating-words, .txt-slot-machine-rotating-words *, .txt-slot-machine-rotating-words::before, .txt-slot-machine-rotating-words::after, .txt-slot-machine-rotating-words *::before, .txt-slot-machine-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.