Skip to content
animorio
IT
Back to the library

Spoiler text

Text, HoverGSAP, CSS onlyMediumCompressed weight: Demo 5.4 KBGSAP 28 KBFreeDownload the zip

A film review with its spoilers hidden: two phrases covered by a flickering grain, letter by letter. Tap one and the grain melts away from left to right while the letters arrive one after the other with a small hop. “Reveal all” uncovers what is left and becomes “Hide again”, which covers everything back; below, the count of how many spoilers are still hidden.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Spoiler text" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Spoiler text</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- a film review with its spoilers covered by a moving grain: tap one and it uncovers letter by letter,
         or uncover them all and cover them again from the button -->
    <article class="sp" data-sp aria-labelledby="sp-title">
      <header class="sp__head">
        <span class="sp__face" aria-hidden="true">M</span>
        <span class="sp__name"><b id="sp-title">The Last Lamp</b><span>Reviewed by Marta V., four out of five</span></span>
      </header>

      <p class="sp__text" data-text>Slow, salty and beautifully lit. I guessed nothing: <span class="sp__hide" data-spoiler>the keeper was her brother all along</span>, and the final shot, where <span class="sp__hide" data-spoiler>the lamp is left burning for no one</span>, stayed with me all night.</p>

      <footer class="sp__foot">
        <span class="sp__count" aria-live="polite"><span data-count>2 spoilers hidden</span></span>
        <button class="sp__all" type="button" data-all><span class="sp__roll"><span data-alllabel>Reveal all</span></span></button>
      </footer>
    </article>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

20 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Spoiler text” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On cream, a light card: a lilac circle with “M”, “The Last Lamp” and “Reviewed by Marta V., four out of five”. Below, the review in large type: “Slow, salty and beautifully lit. I guessed nothing:”, then a covered phrase, “and the final shot, where”, another covered phrase, “stayed with me all night”. The covered parts are words of flickering grey grain, like television snow. At the bottom “2 spoilers hidden” and the violet “Reveal all” button. Tap the first phrase and the grain melts from the left, letter after letter, each letter arriving with a small hop: “the keeper was her brother all along”; the count rolls to “1 spoiler hidden”. “Reveal all” uncovers the second too, the count becomes “Nothing hidden” and the button empties into “Hide again”, which quickly covers both phrases back.

How it works

One cover per letter

The script splits each spoiler into words that do not break and each word into letters. Each letter has a variable from 1 (covered) to 0: the text colour and the opacity of the cover, a pseudo-element, are calc() on it.

The grain

A tile of specks drawn once on a canvas and set as the background of every cover. A few times a second only the background position changes, so the grain flickers without redrawing anything.

Uncovering

GSAP takes each letter’s variable to 0 with a delay growing by STEP seconds from one to the next, and meanwhile gives the letter a small hop and back.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#6a4df4The colour of the button and of the focus ring.
STEPscript.js0.022How many seconds pass between one uncovered letter and the next.
FLICKERscript.js12How many times a second the grain covering the spoiler changes: 0 = still.

Try them in the Playground

When to use it

In reviews of films, series, books and games on a blog or a magazine, in forum comments and chats; and for quiz solutions, exercise answers, the endings of a surprise recipe.

On phones

The same card, as wide as the screen minus the margins: the text wraps by itself and covered words stay whole, never split in the middle. The whole spoiler is tappable. The card is about 290 pixels tall and fits the phone box.

With reduced motion

The grain is still. Tap a spoiler and the phrase appears all at once, with no letters arriving one at a time, and is covered back the same way. The demo’s pointer does not start.

Pitfalls

  • Film and review are made up. The spoiler’s text here is in the page: if it really has to stay secret (the solution of a prize game) it should be fetched from the server only when uncovered.
  • For screen reader users the spoiler is a button that says it is hidden: the text reaches the label only once uncovered.
  • Covered letters have a transparent colour, they are not removed: the line does not change length when the spoiler is uncovered.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 5.4 KB; the libraries: GSAP 28 KB.

Testing

Tested on 25 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations