webdevpuneet.com

Slot Reel Letters — Text That Spins Like a Slot Machine

Slot Reel Letters · Text Animation · Plain HTML, CSS & JS · Live preview

Copy & paste

Source Code

<main class="stage">
  <p class="label">Today's lucky word</p>
  <h1 class="board" id="board" aria-live="polite"></h1>
  <div class="picks" id="picks">
    <button type="button" class="pick on" data-w="JACKPOT">JACKPOT</button>
    <button type="button" class="pick" data-w="WINNER">WINNER</button>
    <button type="button" class="pick" data-w="LUCKY 7">LUCKY 7</button>
    <button type="button" class="pick" data-w="SPIN IT">SPIN IT</button>
  </div>
  <button type="button" class="spin" id="spin">Spin again</button>
</main>

Extend with AI

Take This Snippet Further With AI

Ask an AI coding assistant to explain why spin() calls getBoundingClientRect() between setting the strip's start transform and its transition, and what would happen on a second spin without it. Another good question is why the per-letter duration grows with the index and how the cubic-bezier overshoot creates the stopping bounce.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a slot-machine text reveal in plain HTML, CSS and JavaScript where every letter of a word is its own spinning reel.

Requirements:
- Generate the reels from a string at runtime. Each letter gets a fixed-size window with overflow hidden and a tall vertical strip inside it, holding around sixteen random characters followed by the real letter as the last cell. Spaces become narrow empty gaps.
- To spin, reset each strip to translateY(0), force a layout read so the start position registers, then set a transform transition that moves the strip up so the real letter is in view.
- Stagger the landing: each reel's transition lasts longer than the previous one, and use a cubic-bezier whose end control value is slightly above 1 so each reel overshoots and settles.
- Style the board like a cabinet: a purple gradient frame with a layered outline, cream reel windows with inset top and bottom shadows to suggest a curved drum, and a heavy display font.
- Add chips to pick between several words and a "Spin again" button; changing the word rebuilds and respins.
- Expose the word once with aria-label on a polite live region, hide the reels from assistive technology, and under prefers-reduced-motion skip the animation and show the final word immediately.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

What's included

Features

Real reels, not a fade
Each letter scrolls past random symbols before landing on the real one, so the reveal has a sense of mechanism a fade can't give.
Left-to-right lock-in
Every reel runs a longer transition than the previous one, so the word resolves in order and the eye can follow it.
Overshoot bounce
A cubic-bezier with an end value above 1 makes each reel settle with a small mechanical bounce.
Any string, any length
Reels are generated from the text, including spaces as narrow gaps, so changing the word never means editing markup.
Cabinet styling in CSS
Inset shadows on each window imitate the curve of a drum, and the board has a layered frame, all without images.
Accessible and motion-safe
The word is exposed once through aria-label on a live region, the reels are hidden from screen readers, and reduced-motion visitors get the final word at once.

About this UI Snippet

Slot Reel Letters — Per-Letter Vertical Strips With Staggered Landing

Screenshot of the Slot Reel Letters snippet rendered live

A slot machine doesn't reveal a word by fading it in; it makes you watch symbols blur past until each reel clicks into place. This snippet applies that to text. Every letter of the word is a small window with a tall strip behind it: sixteen random characters followed by the real one. The strip slides up so the real letter ends up in the window, and each reel takes a little longer than the one before it, so the word locks in from left to right.

One strip per letter, built at runtime

JavaScript creates the reels from whatever string you give it, so changing the word is changing one value. Each .strip is a flex column of equal-height cells, and the window around it is overflow:hidden with an inset shadow that fakes the curve of a drum. Spaces become narrow transparent gaps so multi-word phrases like "LUCKY 7" still read as two words.

Why the transition has a slight overshoot

The landing uses cubic-bezier(.2,.8,.25,1.05). The 1.05 end value overshoots by a few percent before settling, which is the small bounce a mechanical reel makes when it stops. Duration grows by 0.22s per letter, and that stagger is what turns sixteen separate transitions into one readable "landing" sequence.

Starting each spin cleanly

Before the transition is set, the code resets the strip to zero and calls getBoundingClientRect() to force a layout, so the browser registers the start position and animates rather than jumping. The board keeps aria-label with the real word, the reels are hidden from assistive tech, and users who prefer reduced motion see the final word immediately.

Step by step

How to Use

  1. 1
    Paste the HTML, CSS and JSA purple cabinet appears and spells JACKPOT by spinning seven reels, then offers three more words as chips and a gold "Spin again" button.
  2. 2
    Set your own wordChange the word variable and the data-w values on the chips. Letters, digits and spaces work; anything outside the POOL string simply lands correctly because the last cell is always the real character.
  3. 3
    Make it longer or shorterSTEPS is how many random symbols scroll past. Raise it for a longer spin; lower it for a quick flick. Remember to keep the duration in step so it doesn't look too fast.
  4. 4
    Change the staggerIn spin(), the duration is 1.1 + i * 0.22 seconds. A smaller multiplier makes the reels land almost together; a larger one gives a slow left-to-right count-in.
  5. 5
    Use it without the buttonsDelete the chips and button and call spin() once on load, or when a section scrolls into view, to use it as a one-off headline reveal.

Real-world uses

Common Use Cases

Giveaway and raffle pages
Reveal the winner's name or a prize code reel by reel, with the spin button replaced by a draw trigger.
Game and casino-style landing pages
Use it for a game title, a daily bonus or a jackpot amount where the mechanical feel matches the theme.
Promo and discount reveals
Spin up a coupon code or a "50% OFF" banner on first visit to give the offer a moment.
Random name or word generators
Pair with a word list so each press spins to a new team name, password idea or writing prompt.
Launch countdown finales
Land the final word of a countdown, such as "LIVE", on the reels once the timer reaches zero.

Got questions?

Frequently Asked Questions

The number of letters and the final character are only known at runtime. JavaScript builds the strips and sets each transition's duration from the letter index, which keyframes with fixed values can't do.

The spin() function rebuilds the strips each time, so each starts at zero. If you reuse strips instead, reset the transform, force a layout with getBoundingClientRect(), then set the transition.

Yes. Replace the POOL string with an array of emoji and pick from it. Keep the cell height equal and give the cells a font that renders emoji evenly.

The last cell shows the character exactly as given, so lowercase and accents land correctly. Only the random filler comes from POOL, so add those characters there if you want the blur to match.