GooseUI

Components

Dither Background

New

An animated background that quantizes a smooth field into two colors with an 8x8 Bayer matrix. It renders to a 2D canvas at low resolution and scales up with crisp pixels. Default colors come from theme tokens and update when the theme changes.

Preview

Switch the pattern, pixel size and speed.

Ship in pixels

Bayer dithering over a moving field

Pattern
Pixel size
Speed

Installation

npx shadcn@latest add @gooseui/dither-background
pnpm dlx shadcn@latest add @gooseui/dither-background
yarn dlx shadcn@latest add @gooseui/dither-background
bunx --bun shadcn@latest add @gooseui/dither-background

Usage

The background fills the nearest positioned parent. Put content after it with relative positioning.

import { DitherBackground } from "@/components/ui/dither-background"

export default function Hero() {
  return (
    <section className="relative h-96 overflow-hidden">
      <DitherBackground />
      <div className="relative">Your content</div>
    </section>
  )
}

Examples

Noise

Drifting value noise with a soft vertical gradient.

<DitherBackground pattern="noise" pixelSize={2} />

Radial pulse

Rings that spread from the center, with large pixels.

<DitherBackground pattern="radial" pixelSize={6} speed={0.6} />

Custom colors

Pass any CSS colors or theme variables. Here the field uses muted tones for a quiet section background.

<DitherBackground
  colorFront="var(--muted-foreground)"
  colorBack="var(--muted)"
  scale={1.6}
/>

Props

PropTypeDefaultDescription
pattern"waves" | "noise" | "radial""waves"Shape of the smooth field before quantization
pixelSizenumber3Size of one dither cell in CSS pixels
speednumber1Animation speed multiplier, 0 freezes the field
colorFrontstring"var(--primary)"Color of lit cells
colorBackstring"var(--background)"Color of unlit cells and the fallback background
scalenumber1Field zoom, higher values give larger shapes
fpsnumber30Frame rate cap
classNamestring-Additional CSS classes for the wrapper

Features

  • Pauses when hidden: the loop stops off screen and in a background tab
  • Bounded cost: work depends on CSS pixels, not devicePixelRatio, and the cell count is capped
  • Theme aware: colors are re-read when the html class or color scheme changes
  • Reduced motion: with prefers-reduced-motion a single static frame is drawn