Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

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…

Read the release notes

data-spoiler

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-spoiler attribute 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.

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.

Options

Attribute Values Description
data-spoiler "", "blur", "solid", "noise" Marks the element as a spoiler. The value sets the effect (default blur).
data-spoiler-label string Reveal button text for this spoiler. Default "Reveal spoiler".
data-spoiler-persist boolean One-way reveal: no Hide button, Escape does nothing.
data-spoiler-group string Mutual exclusion: revealing one spoiler conceals the others with the same group name.
data-spoiler-print "hidden" Spoilers print revealed by default. hidden keeps a still-concealed spoiler hidden on paper (quiz answer sheets).
data-label-spoiler-reveal string Reveal text for every spoiler inside the element (set on <html> or a section). data-spoiler-label on a spoiler wins.
data-label-spoiler-hide string Hide button text. Default "Hide spoiler". Element or ancestor.
data-label-spoiler-revealed string Screen-reader announcement on reveal. Default "Spoiler revealed". Element or ancestor.
data-label-spoiler string Group name given to a generic <div>/<span> host. Default "Spoiler". Element or ancestor.

Set by the script (do not author): data-spoiler-init (structure built; the CSS hook) and data-spoiler-visible (revealed).

Events

Event Detail Description
spoiler:toggle { visible: boolean } Fired on the host (bubbles) when it is revealed or concealed.

Styling

Every rule is gated on [data-spoiler-init], so nothing is concealed without JavaScript. Hooks:

  • [data-spoiler-content] — the wrapper that carries the effect (filter / opacity).
  • [data-spoiler-trigger] > [data-spoiler-label] — the reveal pill.
  • [data-spoiler-hide] — the Hide button.
  • [data-spoiler-visible] — on the host while revealed.

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

Inline, groups, persist, print and localised labels

Dynamic elements

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).
  • data-effect="blur-reveal" — a decorative blur-in entrance, not a concealment control.
  • data-print — other print controls.
  • inert — the native way to make content unusable while it stays visible.
↑