All effectsPlay & loop

Animated Mesh Gradient

流动网格渐变

Several overlapping pockets of color drift independently and blend into each other.

Play or pause the demo

Where to use it

Add movement behind a simple hero section or playback cover. Keep the motion slow behind reading areas and use a steady overlay where foreground contrast needs to stay predictable.

Practical example

A sound library uses drifting blue, lilac, and amber patches behind the cover for its ambient collection. The cover changes gently in the background while track names and playback controls sit on a steady dark panel.

AI prompt

Build an Animated Mesh Gradient for [target surface]. Layer three oversized radial gradients, move their wrappers independently with transform, and keep the edges clipped. Place text over a stable contrast layer. Provide pausing and a static gradient fallback for reduced motion.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Animated Mesh Gradient</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .mesh { width: min(100%, 235px); height: 96px; border-radius: 14px; overflow: hidden; position: relative; background: #152751; border: 1px solid #ffffff2e; }
    .mesh i {
      width: 73%; aspect-ratio: 1; position: absolute; top: -40%; left: -16%;
      background: radial-gradient(circle, #9ac8ff, #7467ed 37%, transparent 72%);
      animation: drift-mesh 5s ease-in-out infinite alternate;
    }
    .mesh i:nth-child(2) {
      top: -20%; left: 27%; background: radial-gradient(circle, #f8bbdf, #d568ae 37%, transparent 72%);
      animation-direction: alternate-reverse; animation-duration: 7s;
    }
    .mesh i:nth-child(3) {
      top: 17%; left: 55%; background: radial-gradient(circle, #a0f1dd, #588fcf 37%, transparent 72%);
      animation-duration: 8s;
    }
    @keyframes drift-mesh { to { transform: translate(32%, -13%) scale(1.18); } }

    .motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
    .motion-specimen {
      display: grid;
      place-items: center;
      width: min(100%, 295px);
      height: 108px;
      position: relative;
      isolation: isolate;
    }
    .motion-example [data-motion] { animation-play-state: paused; }
    .motion-example[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .motion-example [data-motion] { animation: none; }
      .motion-example [data-loop-toggle] { display: none; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="motion-example">
      <div class="motion-specimen" aria-hidden="true"><div class="mesh"><i data-motion></i><i data-motion></i><i data-motion></i></div></div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">Play demo</button>
    </div>
  </main>
  <script>
    const example = document.querySelector('.motion-example');
    const toggle = example.querySelector('[data-loop-toggle]');

    toggle.addEventListener('click', () => {
      const playing = example.toggleAttribute('data-playing');
      toggle.textContent = playing ? "Pause demo" : "Play demo";
    });
  </script>
</body>
</html>

Original example by UI Skills