# Gradient mesh

> A mesh gradient editor. You drag colour points around a live WebGL canvas and they blend smoothly. You can add points with a double click or remove them, recolour a point or the base from a floating glass inspector, add grain, and switch on a drift animation that loops without a seam. It exports as CSS that renders the same image, or as a 2400px PNG.

- Type: Component (special)
- Access: Arc Pro
- Page: https://uiarc.dev/components/gradient-mesh
- Markdown: https://uiarc.dev/components/gradient-mesh/markdown
- Source file: `registry/components/gradient-mesh/gradient-mesh.tsx`
- Dependencies: motion, lucide-react
- Keywords: special, motion, gradient, webgl, new, mesh gradient, background, editor, color, grain, noise, css export, png export, wallpaper, hero, theme, blend, aurora

## When to use

- A settings or brand page where people pick a background for a workspace, profile, hero or card.
- A creative tool that makes wallpapers, covers or social images and needs a soft, controllable gradient.
- A product page that lets visitors play with the look your tool generates.

## When not to use

- Use color-picker to choose one exact color.
- Use a static CSS gradient when nobody needs to edit it.

## Installation

Gradient mesh is part of Arc Pro. The live preview is public; the source and install command need Pro.

### CLI with a Pro token

1. Create a token in your account and set it in the environment (or `.env.local`). Never commit it.

```bash
export ARC_PRO_TOKEN=arc_pro_...
```

2. Add the Pro registry to `components.json`:

```json
{
  "registries": {
    "@uiarc": "https://uiarc.dev/r/{name}.json",
    "@uiarc-pro": {
      "url": "https://uiarc.dev/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${ARC_PRO_TOKEN}"
      }
    }
  }
}
```

3. Install:

```bash
npx shadcn@latest add @uiarc-pro/gradient-mesh
```

### Manual

Signed-in Pro members can copy the source from the Manual tab on the docs page.

- Plans: https://uiarc.dev/pricing
- Create a Pro token: https://uiarc.dev/account#pro-access
- Setup guide: https://uiarc.dev/docs/ai#pro-access

## Usage

```tsx
import { GradientMesh } from "@/components/arc/gradient-mesh/gradient-mesh";

export function HeroBackgroundEditor() {
  return (
    <GradientMesh
      label="Hero background"
      base="#f8efe4"
      points={[
        { color: "#1b2150", x: 0.1, y: 0.92, spread: 0.78 },
        { color: "#5b6cff", x: 0.86, y: 0.16, spread: 0.72 },
        { color: "#ff5f3a", x: 0.2, y: 0.2, spread: 0.62 },
        { color: "#ffb259", x: 0.6, y: 0.64, spread: 0.5 },
      ]}
      onChange={value => saveTheme({ heroMesh: value })}
    />
  );
}
```

## API reference

### GradientMesh

A mesh gradient editor. Color points sit on a live WebGL canvas and blend smoothly into each other. Drag a point to move it, double click the canvas to add one, scroll on a point to change its reach, and recolor the selected point or the base from a floating glass inspector. Randomize builds a whole new design at once: a fresh color scheme, point count, layout, base and grain, which glides into place. A grain control adds film texture, the animate switch lets the mesh drift on a seamless loop, and the design exports as CSS that renders the same image, or as a 2400 pixel PNG.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `points` | `MeshPoint[]` | `Ink, Iris, Vermillion, Apricot, Rose` | Starting points from bottom to top, each with a hex color, x and y as fractions of the canvas (0 to 1 from the top left), and an optional spread (0.15 to 1.2) and id. The component owns them after mount. Three to six read best. |
| `base` | `string` | `"#f8efe4"` | Starting hex color behind every point. |
| `palette` | `MeshSwatch[]` | `Nine swatches from Vermillion to Cream` | Swatches offered in the inspector, each with a name and a hex color. Names are read by screen readers and name the points that use them. A custom color picker is always available. |
| `grain` | `number` | `0.3` | Starting grain, 0 to 1. |
| `animate` | `boolean` | `true` | Starts with the drift on. People can switch it off in the editor. |
| `speed` | `number` | `1` | Multiplies the drift speed; one loop takes 20 seconds at 1. 0 holds it still. Also sets the duration of the exported CSS animation. |
| `paused` | `boolean` | `false` | Holds the drift on its current frame. Editing keeps working. |
| `maxPoints` | `number` | `8` | Most points allowed, 2 to 8. A mesh always keeps at least two. |
| `accent` | `string` | – | Any CSS color for the selection ring on handles and swatches. Defaults to the accent. |
| `hint` | `string` | `"Drag a point to move it. Double click to add one."` | Help shown on the canvas until the first edit. Pass an empty string to hide it. |
| `label` | `string` | `"Gradient mesh"` | Accessible name of the editor. |
| `onChange` | `(value: GradientMeshValue) => void` | – | Called with the saved design (base, grain, animate and every point's id, name, color, x, y and spread) after each change: a drop, a key press, a color, an added or removed point, or a grain step. |
| `onExport` | `(format: "css" \| "png", result: string \| Blob) => void` | – | Called after Copy CSS with the CSS text, or after Save PNG with the image blob. The component still copies and downloads on its own. |
| `mode` | `"editor" \| "background"` | `"editor"` | "background" renders only the mesh, filling its container edge to edge: no handles, inspector, hint, border or radius. It ignores the pointer, is hidden from assistive technology, and follows points, base, grain and animate live, so passing a new palette (on a theme change, say) blends it into place. Place it in a positioned container behind your content. |
| `className` | `string` | – | Class on the root element. |
| `style` | `CSSProperties` | – | Inline styles on the root element. |

## Accessibility

- The root is a labelled group. The canvas is role="img" with a description that lists every color, the base and the grain, and stays current as the mesh changes.
- Each point is a real button with aria-roledescription="draggable point", a label with its number, color, position and size, and aria-pressed for the selected point.
- On a point, arrow keys move it by 1% (Shift 10%, Alt a quarter percent), plus and minus or the bracket keys change its size, Delete removes it and moves focus to its neighbour, and Escape selects the base. The key help is linked with aria-describedby.
- Colors are a radiogroup named for its target (the base or the point) with roving focus: arrows, Home and End pick a color at once. The custom color input and the remove button have specific names.
- Adding, removing, moving, resizing, copying and saving are announced in a polite live region. Copy and save also confirm in place on their buttons, including when they fail.
- Pointer focus draws no ring; keyboard focus shows Arc's shared focus ring. Selection shows through the accent ring on the point and the swatch.

## Motion

- One requestAnimationFrame loop steps critically damped springs and writes WebGL uniforms, handle transforms and the reach ellipse directly; React renders only when the saved design changes.
- A held point follows the pointer on a stiff spring and lets go of the drift; on release the drift eases back in over about a second. Keyboard nudges glide on a softer spring, new points bloom from nothing and removed ones shrink away, and a new color blends in rather than switching.
- The drift is a Lissajous loop per point with integer frequencies, so it repeats without a seam; every point also breathes its size slightly. The drift amount itself eases on and off with the switch.
- The loop stops offscreen, in background tabs, and whenever nothing moves with the drift off or paused.
- With reduced motion the drift switch is off and disabled, the mesh is still and every edit lands at once; all editing and exporting still work.

## Responsive behavior

- The canvas keeps a 16:9 ratio on wide containers and becomes square below 640 pixels of container width; positions are fractions, so the design survives the change.
- The inspector floats as a glass bar over the canvas when there is room and docks under it on narrow containers, with the swatches on their own row.
- Handles have a 44 pixel hit area and are clamped inside the canvas even when their point sits on an edge. Touches outside a handle still scroll the page.

## Performance

- The mesh is one fragment shader over a full screen triangle, up to eight points, at no more than twice the device pixel ratio.
- Idle frames write nothing: the loop stops when springs settle and the drift is off, and DOM writes are skipped when a value has not changed.
- The loop never reads layout; the canvas size is cached by a ResizeObserver and pointer math reads the canvas rectangle once per drag.

## Notes for AI

- Use it where someone designs a background: a theme or brand settings page, a hero or cover editor, a slide or social card maker, or a wallpaper generator.
- The exported CSS is the same model the canvas draws: a base color plus one elliptical radial gradient per point with a smoothstep falloff, so it matches the editor. Grain is an SVG noise layer blended with overlay and reads slightly softer than on the canvas.
- With animate on, the CSS registers custom properties with @property and adds a keyframed drift that respects prefers-reduced-motion.
- Colors are hex. Points paint in order, so later points sit on top. Point positions are fractions of the canvas, so the design scales to any aspect ratio.
- Save PNG needs WebGL; without it the canvas falls back to live CSS and the button is disabled.

## Related

- [Color picker](https://uiarc.dev/components/color-picker/markdown): A swatch that grows into a picker with format morphing, eyedropper, saved swatches, and contrast readout.
- [Ink fluid](https://uiarc.dev/components/ink-fluid/markdown): A real time fluid simulation behind your hero: the cursor stirs soft ink that swirls, settles and fades; calm when left alone.

## Also in galleries

- [Product gallery](https://uiarc.dev/components/product-gallery/markdown): A product gallery with a hover magnifier, gliding thumbnails, and color and size variants that crossfade photos.
- [Lightbox gallery](https://uiarc.dev/components/lightbox-gallery/markdown): A masonry grid where photos zoom from their slot into a viewer you can swipe, pinch, and drag away.
- [Photo grid](https://uiarc.dev/components/photo-grid/markdown): Pinch through zoom levels and open any photo straight from its cell.
- [Cover flow](https://uiarc.dev/components/cover-flow/markdown): A depth rail of images you can throw, with soft grounded shadows and a quiet reflection.
- [Infinite moodboard](https://uiarc.dev/components/infinite-moodboard/markdown): An endless board of photos you can throw around with momentum, where a click grows any photo to fill the frame.

## Guidance for AI tools

Gradient mesh: A mesh gradient editor. You drag colour points around a live WebGL canvas and they blend smoothly. You can add points with a double click or remove them, recolour a point or the base from a floating glass inspector, add grain, and switch on a drift animation that loops without a seam. It exports as CSS that renders the same image, or as a 2400px PNG. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://uiarc.dev/llms.txt
