# Mesh gradient

Three to five colour blobs that drift and melt into each other, drawn as a dither, for heroes and sign-up screens.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. The dithercn agent skill, for building any dither on the engine, is at [/.well-known/agent-skills/dithercn/SKILL.md](/.well-known/agent-skills/dithercn/SKILL.md).

<ComponentPreview src="examples/mesh-gradient-demo.tsx" size="full" align="stretch" controls="meshGradientControls">
  <MeshGradientDemo />
</ComponentPreview>

## Installation [#installation]

<InstallBlock name="mesh-gradient" />

## Usage [#usage]

```tsx
import { MeshGradient } from "@/components/dithercn/mesh-gradient";

export function Hero() {
  return (
    <section className="relative isolate min-h-[480px]">
      <MeshGradient className="absolute inset-0 -z-10" />
      <h1>Your headline</h1>
    </section>
  );
}
```

Each blob drifts on its own slow orbit. Where two meet, their colours blend through the palette before the dither, so the seams read as soft gradients instead of edges. The default palette uses tints of your theme's `--dither-ink` with a touch of violet.

## Examples [#examples]

### Five blobs, warm palette [#five-blobs-warm-palette]

`palette` starts with paper and then takes one colour per blob. Pass `blobs + 1` colours to give each blob its own; the order sets which colours sit next to each other where blobs meet. Blue noise, the default, keeps the grain even across so many tones.

<ComponentPreview src="examples/mesh-gradient-sunset.tsx" size="lg" align="stretch">
  <MeshGradientSunset />
</ComponentPreview>

### Behind a form [#behind-a-form]

Three large blobs, bigger cells and a slower `speed` make a calm backdrop. The form sits on a translucent panel so the colour shows around it without hurting the text.

<ComponentPreview src="examples/mesh-gradient-signup.tsx" size="lg" align="stretch">
  <MeshGradientSignup />
</ComponentPreview>

## Props [#props]

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `blobs` | `3 \| 4 \| 5` | `4` | How many colour blobs drift across the box. |
| `size` | `number` | `0.6` | Size of each blob as a share of the box height. |
| `palette` | `[DitherColor, DitherColor, ...DitherColor[]]` | `Paper, then four tints of --dither-ink` | Colours from paper to ink: palette names such as "blue", CSS variable names, or any CSS colour. |
| `matrix` | `"bayer2" \| "bayer4" \| "bayer8" \| "blue-noise"` | `"blue-noise"` | The threshold pattern. See Dither engine. |
| `cell` | `number` | `--dither-cell` | Size of one dither cell in CSS pixels. |
| `speed` | `number` | `1` | How fast it moves. |
| `animate` | `boolean` | `true` | false draws one still frame. |
| `className` | `string` | `–` | Size and position. The background fills this box. |

## Notes [#notes]

* It is decorative and hidden from assistive technology. Put real text on top of it, not inside it.
* With reduced motion turned on, it draws one still frame and stops.
* It pauses when scrolled out of view or when the tab is hidden, and releases its WebGL context when far offscreen. Without WebGL it shows a CSS approximation in the same colours.
* It costs one small draw per frame at 30 fps, at one pixel per dither cell. See [Performance](/docs/engine/performance).