0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Hide content behind blur, solid, or noise overlays until the reader chooses to reveal it. Works on any element, keeps its semantics, and supports keyboard, screen readers, localisation and print.
Overview
The data-spoilerattribute conceals content until the reader chooses to reveal it: plot spoilers, quiz answers, punchlines. Add the attribute to any element; no wrapper is needed. Without JavaScript the content is simply visible.
Basic blur spoiler
123
<sectiondata-spoiler><p>Darth Vader is Luke's father.</p></section>
Usage
The script moves the element's children into a [data-spoiler-content] wrapper made inert, and adds a <button data-spoiler-trigger> over it.
Click, Enter or Space on the trigger reveals the content and moves focus to it.
Escape (focus inside a revealed spoiler) or the Hide spoiler button conceals it again and returns focus to the trigger, unless data-spoiler-persist is set.
The wrapper is a <span> unless the host accepts flow content (<section>, <li>, <td>, custom elements…), so spoilers inside <p>, headings and inline text stay valid HTML.
Spoilers added later, cloned with cloneNode() or restored from saved markup work without set-up: one delegated listener serves every trigger and Hide button.
Transitions are instant under prefers-reduced-motion. In print, spoilers are revealed and the buttons hidden unless data-spoiler-print="hidden" is set.
Accessibility
Concealed content is inert: screen readers cannot read it and the keyboard cannot reach it.
The trigger is a real <button> (also inside <p>, where buttons are valid) with aria-expanded.
Revealing moves focus to the revealed content, so keyboard and screen-reader users continue reading where the trigger was. Concealing returns focus to the trigger.
The host keeps its own semantics: a list item stays a list item, a heading stays a heading. Only a generic <div> or <span> without a role or label gets role="group" and the "Spoiler" name.
"Spoiler revealed" is announced through the shared polite live region on <body>.
Every string is localisable with data-label-* on the spoiler or an ancestor; the Hide button says "Hide spoiler" so several on a page are not just "Hide".
Without JavaScript the content is fully visible.
Examples
Effects
Blur, solid and noise
123
<pdata-spoiler="blur">Visible but unreadable behind a blur.</p><pdata-spoiler="solid">Fully hidden behind a solid bar.</p><pdata-spoiler="noise">Faintly visible through a noise pattern.</p>
Inline, groups, persist, print and localised labels
Options
123456789101112131415
<p>In the movie, <spandata-spoiler>the butler did it</span>.</p><ol><lidata-spoilerdata-spoiler-group="quiz"data-spoiler-label="Show answer 1"data-spoiler-print="hidden">Paris — no</li><lidata-spoilerdata-spoiler-group="quiz"data-spoiler-label="Show answer 2"data-spoiler-print="hidden">London — no</li><lidata-spoilerdata-spoiler-group="quiz"data-spoiler-label="Show answer 3"data-spoiler-print="hidden">Tokyo — yes</li></ol><pdata-spoilerdata-spoiler-persistdata-spoiler-label="Show answer">Once revealed, this stays visible.</p><sectiondata-label-spoiler-reveal="Afficher le spoiler"data-label-spoiler-hide="Masquer le spoiler"data-label-spoiler-revealed="Spoiler affiché"><plang="fr"data-spoiler>Le majordome est coupable.</p></section>
Dynamic elements
Added later: enhanced automatically
1234
const el = document.createElement('p');el.dataset.spoiler = 'blur';el.textContent = 'Hidden content';document.querySelector('main').append(el);
Related
<details> / <summary> — the native disclosure. Which to choose: use <details> when the hidden part is extra content behind a labelled summary (FAQ answers, "show more"); it needs no JavaScript and collapses the space. Use data-spoiler when the content should stay in place and in layout, visibly obscured, and the reader opts in to seeing it (plot twists, quiz answers).