webdevpuneet.com

Number Slot Machine — Free HTML CSS JS Snippet

Number Slot Machine · Loaders · Plain HTML, CSS & JS · Live preview

CategoryLoaders

Copy & paste

Source Code

<div class="scene">
  <div class="display">
    <div class="slot-wrap" id="display"></div>
    <span class="currency">USD</span>
  </div>
  <div class="btns">
    <button class="btn" onclick="spinTo(Math.floor(Math.random()*9000+1000))">Random</button>
    <button class="btn accent" onclick="spinTo(99999)">Max</button>
    <button class="btn" onclick="spinTo(0)">Reset</button>
  </div>
  <p class="hint">Each digit spins independently to its target</p>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Each digit is an overflow: hidden container with a 0-9 column inside
translateY(-digit * height) selects the visible digit in each column
CSS transition on the column element creates the rolling animation
Random intermediate values create the spinning-through effect before settling
Each column settles at a slightly different time for authentic slot feel
Configurable digit count via DIGITS constant
Dark display panel aesthetic matching scoreboards and counters
Export as HTML file, React JSX, or React + Tailwind CSS
Mobile (375px), Tablet (768px), Desktop device preview buttons
Live split-pane editor — preview updates as you type

About this UI Snippet

Number Slot Machine — translateY Digit Column Scroll & Eased Animation

Screenshot of the Number Slot Machine snippet rendered live

A number slot machine animates digits rolling like a slot machine — each digit column spins through 0-9 and settles on the target number. Used on count-up hero sections, lottery-style reveals, and any metric display that benefits from a reveal animation.

The digit column structure

Each digit position is a container showing one digit at a time (overflow: hidden). Inside is a column of divs for digits 0-9. The visible digit is controlled by translateY(-index * height) — translating the column up to reveal the digit at the target index.

The roll animation

When a new number is set, each digit column animates from its current position through several random intermediate values before settling on the target digit. The animation uses requestAnimationFrame with easing, and each column has a slightly different timing to create the authentic slot machine feel where digits settle at different moments.

Use cases

Live counters that update when new data arrives, lottery number reveals, and score displays all benefit from this animation pattern.

The column scroll mechanism

Each digit column contains all 10 digits (0-9) stacked vertically. To show digit 7, the column translates to translateY(-700%). The CSS transition: transform 0.3s cubic-bezier(0.4,0,0.2,1) animates the column scrolling to the target digit. overflow: hidden on the digit window clips the column to show only one digit at a time. For a multi-digit display, each column animates independently with a small staggered delay creating the cascading slot machine roll effect.

Triggering and reset

A spin() function picks random target digits and sets each column transform. A staggered animation-delay per column creates the sequential reveal. For a score or counter display, animate to the actual value instead of a random number — compute the target digit for each column position from the number string.

Sound integration

For a complete slot machine experience, add a Web Audio API click sound on each column stop. Create a brief 440Hz tone that fades in 0.02s and out in 0.03s using an OscillatorNode and GainNode. Trigger one sound per column as each settles, staggered by the same delay as the visual animation.

The column scroll mechanism

Each digit column contains all 10 digits (0-9) stacked vertically. To show digit 7, the column translates to translateY(-700%). The CSS transition: transform 0.3s cubic-bezier(0.4,0,0.2,1) animates the column scrolling to the target digit. overflow: hidden on the digit window clips the column to show only one digit at a time. For a multi-digit display, each column animates independently with a small staggered delay creating the cascading slot machine roll effect.

Triggering and reset

A spin() function picks random target digits and sets each column transform. A staggered animation-delay per column creates the sequential reveal. For a score or counter display, animate to the actual value instead of a random number — compute the target digit for each column position from the number string.

Sound integration

For a complete slot machine experience, add a Web Audio API click sound on each column stop. Create a brief 440Hz tone that fades in 0.02s and out in 0.03s using an OscillatorNode and GainNode. Trigger one sound per column as each settles, staggered by the same delay as the visual animation.

Step by step

How to Use

  1. 1
    Watch the digits rollThe number slot machine spins each digit through 0-9 before settling on the target number.
  2. 2
    Click to generate a new numberClick the button to spin to a new random number.
  3. 3
    Change the number of digitsUpdate const DIGITS = 5 in the JS panel.
  4. 4
    Set a specific target numberReplace the random logic with a specific number: spinTo([1,2,3,4,5]).
  5. 5
    Change spin speedUpdate the animation timing values in the spin logic in the JS panel.
  6. 6
    Export in your formatClick "HTML" for a standalone file, "JSX" for a React component, or "Tailwind" for a React + Tailwind version.

Real-world uses

Common Use Cases

Lottery and prize reveal animations
Animate a prize draw by spinning to the winning number. The slot machine aesthetic adds anticipation.
Live score and counter displays
Animate score changes in a game or points system. The rolling digit communicates that the value has updated — for a simple ticking total, the count-up counter is lighter weight.
OTP and verification code reveals
Animate one-time code display alongside an OTP input — each digit rolls in sequentially for a more engaging code presentation.
Learn CSS translateY digit column technique
The slot uses translateY to scroll through a column of digits. Edit the column height and translateY calculation to understand the positioning.
Dashboard metric animated updates
When a live metric updates, spin the changed digits only — the unchanged digits remain still while updated ones roll to new values.
Countdown timer with slot animation
Wire to a countdown timer: update the digit arrays each second and call spinTo(). The rolling animation makes countdown timers more visually engaging.
Related: Diagonal Shimmer Skeleton
See the Diagonal Shimmer Skeleton for a related loaders pattern worth pairing with this one.

Got questions?

Frequently Asked Questions

Each slot position has an overflow: hidden container showing one row. Inside is a column with divs for each digit 0-9. translateY(-index * rowHeight) scrolls the column to show the digit at that index position.

Before transitioning to the target digit, the column first scrolls through several random intermediate digit values. The rapid changes create the visual "spinning" before the final slow settle.

Replace the random digit generation with your target: const target = [7,4,2]; // for 742. Pass this array to the spin function. The digits roll and settle on exactly these values.

Track the previous value and only trigger the spin animation on columns where the digit changed. Keep unchanged columns at their current translateY position.

Yes. Click "JSX" for a React component. Manage the digit array in useState. Trigger the animation in a useEffect when the values change, using CSS transitions on the column elements via useRef.

After every third digit from the right, insert a separator element between the slot columns in the HTML. Style it as a static comma character between the animated digit columns.