Dither

stable 1.4 kB
<hk-dither>

A Bayer 4×4 threshold matrix over a drifting gradient. Drawn as cells rather than per-pixel on purpose: a true per-pixel dither means writing millions of bytes into an ImageData every frame, which is exactly what makes a background library unusable. A 4px cell is visually identical here and costs a sixteenth.

#background#canvas#decorative

Live demo

Running in this page — interact with it.

Inputs

NameTypeDefaultDescription
colorstring'#dc2626'Base colour. Any hex the background derives its palette from.
speednumber1Animation multiplier. 0 freezes on the first frame.
opacitynumber1Canvas opacity — these sit behind real content.
pausedbooleanfalseStops the loop without unmounting.
pixelSizenumber4Cell edge in px. Larger is chunkier and cheaper.
noisenumber0.08Extra sparkle, 0–1. Hashed per cell, not random per frame.
intensitynumber0.34Cell opacity. Dithering stays binary per cell, so subtlety comes from alpha.
sparsitynumber0.34Raises the threshold so fewer cells light up. 0–1, higher is sparser.

Theming

Component tokens, each falling back to a global one:

PropertyDefaultControls
--hk-bg-color#dc2626Base hue. Every background derives its palette from it.

Accessibility

  • The canvas is aria-hidden — a decorative layer must never be announced.
  • Under prefers-reduced-motion it paints one frame and never starts the loop.
  • The loop stops when the element scrolls out of view and when the tab is hidden, so an offscreen background costs nothing.
  • Frames run outside the Angular zone, so animating never triggers change detection in the rest of the app.

More in Backgrounds