CSS Spoiler Text
Blurred spoiler text that comes into focus on hover, tap or keyboard focus, like on forums and chats.
The killer was the butler.
<p class="spoiler-note">The killer was <span class="spoiler-blur" tabindex="0">the butler</span>.</p>
.spoiler-note {
max-width: 14em;
margin: 0;
color: #0f172a;
font: 500 22px/1.5 system-ui, sans-serif;
}
.spoiler-blur {
padding: 0 0.2em;
border-radius: 0.3em;
background: #e2e8f0;
color: transparent;
text-shadow: 0 0 0.35em #0f172a;
-webkit-box-decoration-break: clone;
box-decoration-break: clone;
cursor: pointer;
transition: color 0.25s ease, text-shadow 0.25s ease;
}
.spoiler-blur:hover,
.spoiler-blur:focus {
color: inherit;
text-shadow: none;
}
.spoiler-blur:focus-visible {
outline: 2px solid #2563eb;
outline-offset: 2px;
}
About this CSS Spoiler Text
This CSS Spoiler Text is 29 lines of pure CSS (0.6 KB) with no JavaScript and no dependencies. It uses transitions, text shadows and keyboard focus styles. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#0f172a#e2e8f0#2563eb
How to use this spoiler text
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.spoiler-noteclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.