Animated gradient background in React and Next.js

Ribbonwash exports your animated mesh gradient as a ready-made React component, MeshBackground.jsx. The gradient fills the component and your content renders on top. It works with Vite, Create React App and Next.js, and React 17 or newer is its only dependency.

Open the editor — freeGet Pro · $19

Live: an exported scene behind a heading, the same layout as the Example.jsx file in the export.

Add it to your app in 4 steps

  1. Design the gradient

    Make your scene in the editor, or start from a template (Artworks → New artwork…).

  2. Export the React component

    Choose Export → Code…. The React component tab shows MeshBackground.jsx; Complete ZIP → Download ZIP gives you it together with the files it needs (code export is part of Pro ($19, one-time)).

  3. Copy the react/ folder

    Unzip and copy the react/ folder into your project. It works with any bundler that can import JSON — Vite, Next.js, Create React App.

  4. Render it

    import MeshBackground from './react/MeshBackground' and wrap your hero in it. The gradient fills the component; children render on top.

What's in the react/ folder

FileWhat it is
MeshBackground.jsxThe component (below).
Example.jsxA full-screen usage example.
mesh-runtime-react.jsThe runtime and the React wrapper in one file, with no other dependency.
scene.jsonYour scene: curves, colors and motion.
poster.jsThe first frame as an image. It shows before WebGL starts and whenever the animation can't run.

MeshBackground.jsx

This is the file the export writes, unchanged:

// Ribbonwash · mesh gradient background — React 17+
// 用法 / Usage:
//   import MeshBackground from './MeshBackground';
//   <MeshBackground style={{ minHeight: '100vh' }}><h1>Hello</h1></MeshBackground>
// 渐变铺满组件作为背景,children 显示在上层。 The gradient fills the component; children render on top.
import { MeshGradientView } from './mesh-runtime-react.js';
import scene from './scene.json';
import poster from './poster.js';

export default function MeshBackground({ children, className, style, playing = true, ...options }) {
  return (
    <div className={className} style={{ position: 'relative', overflow: 'hidden', ...style }}>
      <MeshGradientView
        scene={scene}
        playing={playing}
        poster={poster}
        {...options}
        style={{ position: 'absolute', inset: 0, zIndex: 0, pointerEvents: 'none',
          background: `${scene.background} url(${poster}) center / cover no-repeat` }}
      />
      <div style={{ position: 'relative', zIndex: 1 }}>{children}</div>
    </div>
  );
}

And Example.jsx:

import MeshBackground from './MeshBackground';

export default function Example() {
  return (
    <MeshBackground style={{ minHeight: '100vh', display: 'grid', placeItems: 'center', color: '#fff' }}>
      <h1>Hello, gradient</h1>
    </MeshBackground>
  );
}

Props

PropWhat it does
childrenYour content, rendered above the gradient.
style, classNameApplied to the outer <div>. Give it a height here (for example minHeight: '100vh').
playingtrue by default. Pass false to pause; true resumes.
onReadyCalled once with the gradient instance (pause(), play(), destroy()).
speed, fit, pixelRatio, modeRuntime options: playback speed, 'cover' fit (default), the device-pixel-ratio cap, and 'embed' mode (default).
degradeBelowFps, freezeBelowFps, freezeAfterMsPerformance guard: lower resolution below 24 fps, hold a still frame below 15 fps for 4000 ms (the defaults).
respectReducedMotiontrue by default: visitors who prefer reduced motion see a still frame.

Runtime options are read once, when the component mounts. playing and the wrapper's scene prop are applied live. A play/pause toggle:

import { useState } from 'react';
import MeshBackground from './react/MeshBackground';

export default function Hero() {
  const [playing, setPlaying] = useState(true);
  return (
    <MeshBackground playing={playing} style={{ minHeight: '70vh' }}>
      <button onClick={() => setPlaying(p => !p)}>{playing ? 'Pause' : 'Play'}</button>
    </MeshBackground>
  );
}

Next.js (App Router) and SSR

The gradient needs the browser (WebGL and an effect hook), so render it from a Client Component: add 'use client' to the top of the file that uses it.

// app/Hero.jsx
'use client';
import MeshBackground from './react/MeshBackground';

export default function Hero() {
  return (
    <MeshBackground style={{ minHeight: '100vh', display: 'grid', placeItems: 'center', color: '#fff' }}>
      <h1>Hello, gradient</h1>
    </MeshBackground>
  );
}
// app/page.jsx (a Server Component)
import Hero from './Hero';

export default function Page() {
  return <Hero />;
}

Size and performance

FAQ

Does it work with Next.js Server Components?

Yes, as a Client Component. Put 'use client' at the top of the file that renders MeshBackground, then use that component from any server page or layout. The server renders the empty container with the poster as its background, and the canvas starts in the browser.

Which React versions are supported?

React and React DOM 17 or newer. There are no other dependencies.

Can I swap the scene at runtime?

The wrapper applies a new scene prop without remounting. The exported MeshBackground.jsx imports its own scene.json, so to switch scenes, edit it to take scene as a prop and pass in other exported JSON files.

Does production need a license key?

No. The exported component and runtime have no license check and never call home. They keep working offline, forever.

Open the editor — freeGet Pro · $19