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

text-reader

Text-to-speech reader with word-level highlighting. Uses the Web Speech API for synthesis and the CSS Custom Highlight API for word tracking.

Overview

The <text-reader> component attaches a text-to-speech control bar to any element. It uses the Web Speech API for synthesis and the CSS Custom Highlight API for real-time word tracking. Progressive enhancement — the component hides itself if the browser lacks speechSynthesis.

Attributes

AttributeTypeDefaultDescription
forstring—ID of the element to read. Required.
variantstring—Set to "icon" for a compact speaker icon with floating mini-toolbar
selectorsstringp,liComma-separated CSS selectors for text extraction within the target
speednumber1Initial playback rate (0.5–2)
voicestring—voiceURI to pre-select on load
highlightstring—Set to "false" to disable word highlighting
scrollstring—Set to "false" to disable auto-scroll to active word

Labels and Language

Every generated string can be overridden with a data-label-* attribute. English is the fallback.

AttributeDefaultUsed for
data-label-playPlayPlay button
data-label-pausePausePause button
data-label-stopStopStop button
data-label-readerArticle readerControl-bar group and icon trigger
data-label-controlsReader controlsIcon-variant toolbar group
data-label-voiceVoiceVoice select
data-label-loading-voicesLoading voices…Voice select placeholder
data-label-speedSpeedSpeed slider
data-label-slower / data-label-fasterSlower / FasterIcon-toolbar speed buttons

The reading language comes from the nearest lang attribute on the target (falling back to <html lang>). It is set on the utterance, and voices for that language are listed and selected first, so a French article in an English page is read with a French voice.

What Gets Read

  • Elements matching selectors (default p,li) inside the target, in document order.
  • Matches inside <pre>, <code> or an aria-hidden="true" / hidden subtree are skipped entirely.
  • Inside a matched paragraph, text in aria-hidden="true", hidden, <script>, <style> and <template> descendants is skipped, so decorative icons are not spoken.
  • The text is re-extracted every time playback starts, so content added after load is included.
  • Literal < and > are replaced with spaces before speaking; speech engines otherwise treat them as SSML and stop silently.

Observed Attributes

These attributes are reactive — changing them at runtime triggers an update:

AttributeBehavior on Change
speedRestarts speech from the current word at the new rate
voiceRestarts speech from the current word with the new voice
forStops current speech, re-resolves target element

JavaScript API

Method / PropertyTypeDescription
play()methodBegin playback (or resume if paused)
pause()methodPause mid-sentence
resume()methodResume from paused state
stop()methodCancel speech and reset position
voicesPromise<SpeechSynthesisVoice[]>Available TTS voices
speakingbooleanWhether speech is currently active
pausedbooleanWhether speech is paused
progressnumber (0–1)Current position as fraction of total text

Events

EventDetailWhen
text-reader:play{ voice, speed }Speech starts
text-reader:pause—Speech paused
text-reader:resume—Speech resumed
text-reader:stop—Stopped or cancelled
text-reader:end{ duration }Reached end of text
text-reader:word{ word, charIndex, element }Each word boundary
text-reader:error{ error }SpeechSynthesis error

CSS Custom Properties

PropertyDefaultDescription
--text-reader-bgvar(--color-surface-raised)Control bar background
--text-reader-gap0.5remGap between controls
--text-reader-button-size2remButton width and height
--text-reader-highlightMarkWord highlight background color
--text-reader-highlight-textMarkTextWord highlight text color

Custom Icons

Replace the default text symbols with custom icons using slot attributes:

Any element with slot="icon-play", slot="icon-pause", or slot="icon-stop" will be moved into the corresponding button.

Icon Variant

Use variant="icon" for a compact speaker icon that opens a floating mini-toolbar on click. Ideal for article toolbars and <page-tools> integration.

The floating toolbar provides play/pause, stop, and speed controls. It appears above the trigger icon and auto-dismisses when reading ends. Click outside the toolbar to hide it without stopping playback; click the trigger again to re-show it.

The toolbar follows the trigger in the DOM, so Tab from the trigger moves straight into it. It is shown in the top layer (a manual popover), so transformed or contained ancestors can't clip it. With focus on the trigger or inside the toolbar, Escape hides it and moves focus to the trigger. Escape pressed elsewhere on the page is left alone; a click outside also hides the toolbar. Hiding the toolbar does not stop speech: use the Stop button, or press the trigger to bring the toolbar back.

Customize the trigger icon with slot="icon-trigger":

Accessibility

  • Controls are wrapped in a role="group" with aria-label="Article reader"
  • Each button has an aria-label (customizable via data-label-* attributes)
  • All controls are keyboard-focusable and operable. When Play and Pause swap, focus moves to the button that replaces the one you pressed, and to Play when Stop becomes disabled.
  • Auto-scroll to the spoken word is instant (no smooth scrolling) under prefers-reduced-motion: reduce
  • Transport buttons keep a visible border in forced-colours mode
  • Only one reader speaks at a time. Starting one cancels the other, which resets and fires text-reader:stop; a reader that isn't speaking never cancels another's speech
  • Voice select and speed slider have accessible labels
  • Highlighting uses system colors (Mark / MarkText) by default, respecting user contrast preferences
  • Speech is cancelled on page unload to prevent orphaned audio

Browser Support

FeatureChromeFirefoxSafariNotes
Web Speech API33+49+7+Core feature
CSS Custom Highlight API105+117+17.2+Word highlighting only
Custom Elements67+63+10.1+Baseline
adoptedStyleSheets73+101+16.4+Highlight injection

Graceful Degradation

ConditionBehavior
No speechSynthesisElement hides itself (display: none)
No CSS.highlightsSpeech works normally, highlighting skipped
No target foundConsole warning, controls disabled
↑