Three reels spin with motion blur and stop one after another, each overshooting a touch before it settles on 7, then JACKPOT fades in. Each reel is a digit strip with its own duration.
Also known as: slot machine css, jackpot number spin, spinning digits animation.
<div class="txt-slot-machine-numbers" aria-label="777, jackpot"> <div class="txt-slot-machine-numbers-frame" aria-hidden="true"><span class="txt-slot-machine-numbers-reel" style="--to: 24; --i: 0"><span>3456789012345678901234567</span></span><span class="txt-slot-machine-numbers-reel" style="--to: 39; --i: 1"><span>8901234567890123456789012345678901234567</span></span><span class="txt-slot-machine-numbers-reel" style="--to: 46; --i: 2"><span>12345678901234567890123456789012345678901234567</span></span></div> <span class="txt-slot-machine-numbers-win">Jackpot</span> </div>
.txt-slot-machine-numbers {
--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;
align-items: center;
gap: 0.3em;}
.txt-slot-machine-numbers-frame {
display: flex;
gap: 0.14em;
padding: 0.16em;
border-radius: 0.35em;
background: var(--c);
box-shadow: 0 0.2em 0.5em -0.2em color-mix(in srgb, var(--c) 70%, transparent);
}
.txt-slot-machine-numbers-reel {
position: relative;
width: 0.95em;
height: 1.2em;
overflow: hidden;
font-size: 1.9em;
line-height: 1.2;
text-align: center;
font-variant-numeric: tabular-nums;
color: color-mix(in srgb, var(--c) 75%, #000);
background: #fff;
border-radius: 0.14em;
}
/* shading makes the flat strip read as a drum */
.txt-slot-machine-numbers-reel::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(rgb(0 0 0 / 0.3), transparent 32%, transparent 68%, rgb(0 0 0 / 0.3));
}
.txt-slot-machine-numbers-reel > span {
display: block;
width: 1ch;
margin: 0 auto;
word-break: break-all;
--d: calc(1.2s + var(--i) * 0.45s);
animation:
txt-slot-machine-numbers-spin var(--d) forwards,
txt-slot-machine-numbers-blur var(--d) ease-in forwards;
}
.txt-slot-machine-numbers-win {
font-size: 0.55em;
font-weight: 800;
letter-spacing: 0.3em;
text-transform: uppercase;
color: var(--c);
opacity: 0;
animation: txt-slot-machine-numbers-win 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 2.2s forwards;
}
/* fast spin that brakes, runs a little past the digit, and settles back */
@keyframes txt-slot-machine-numbers-spin {
0% { transform: translateY(0); animation-timing-function: cubic-bezier(0.3, 0.5, 0.4, 1); }
90% { transform: translateY(calc(var(--to) * -1.2em - 0.28em)); animation-timing-function: ease-in-out; }
to { transform: translateY(calc(var(--to) * -1.2em)); }
}
@keyframes txt-slot-machine-numbers-blur {
0% { filter: blur(0.05em); }
85% { filter: blur(0.02em); }
100% { filter: blur(0); }
}
@keyframes txt-slot-machine-numbers-win {
from { opacity: 0; transform: scale(0.6); }
to { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
.txt-slot-machine-numbers, .txt-slot-machine-numbers *, .txt-slot-machine-numbers::before, .txt-slot-machine-numbers::after, .txt-slot-machine-numbers *::before, .txt-slot-machine-numbers *::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.