# Mesh gradient

> Five soft blobs of color that melt into each other and drift slowly, like a living gradient.

- Category: [Backgrounds](https://library.aimran.es/components/patterns)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/pt-mesh
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

A mesh gradient is a safe choice for the hero of a SaaS landing page, the cover of a design portfolio or a waitlist page. You get color and slow movement with no shapes fighting your headline. It’s an animated gradient background in plain HTML and CSS, so there’s nothing extra to load.

Pick colors that sit close on the color wheel, blue and violet for example, and the blend stays smooth. Strongly opposite colors turn muddy where they meet. If white text sits on top, drop the opacity a little or add a dark overlay behind the copy.

## Code

### HTML

```html
<div class="pt-mesh"><i></i><i></i><i></i><i></i><i></i></div>
```

### CSS

```css
.pt-mesh {
  --c1: #0071e3;
  --c2: #8b5cf6;
  --c3: #14b8a6;
  --k: 1;
  /* velocidad */
  --d: 1;
  /* densidad / escala */
  --o: 1;
  /* opacidad */
  --bg: #05060a;
  --fg: #ffffff;
  --blend: screen;
  min-height: 100vh;
}

.pt-mesh {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-mesh>* {
  opacity: var(--o);
}

.pt-mesh i {
  position: absolute;
  width: calc(90% * var(--d));
  aspect-ratio: 1;
  border-radius: 50%;
  -webkit-mask: radial-gradient(closest-side,#000,transparent);
  mask: radial-gradient(closest-side,#000,transparent);
  will-change: transform;
  animation: pt-mesh-a calc(20s / var(--k)) ease-in-out infinite alternate;
}

.pt-mesh i:nth-child(1) {
  background: var(--c1);
  left: -12%;
  top: -15%;
}

.pt-mesh i:nth-child(2) {
  background: var(--c2);
  right: -12%;
  top: 5%;
  animation-name: pt-mesh-b;
}

.pt-mesh i:nth-child(3) {
  background: var(--c3);
  left: 15%;
  bottom: -25%;
  animation-name: pt-mesh-c;
  animation-duration: calc(24s / var(--k));
}

.pt-mesh i:nth-child(4) {
  background: color-mix(in srgb,var(--c1),var(--c2));
  right: 5%;
  bottom: -15%;
  animation-direction: alternate-reverse;
}

.pt-mesh i:nth-child(5) {
  background: color-mix(in srgb,var(--c3) 70%,#fff);
  left: 38%;
  top: 28%;
  width: calc(34% * var(--d));
  animation-name: pt-mesh-b;
  animation-duration: calc(16s / var(--k));
}

@keyframes pt-mesh-a {
  0% {
    transform: translate(0,0) scale(1);
  }
  50% {
    transform: translate(30%,20%) scale(1.2);
  }
  100% {
    transform: translate(-10%,40%) scale(.9);
  }
}

@keyframes pt-mesh-b {
  0% {
    transform: translate(0,0) scale(1);
  }
  50% {
    transform: translate(-35%,25%) scale(.85);
  }
  100% {
    transform: translate(-10%,-20%) scale(1.15);
  }
}

@keyframes pt-mesh-c {
  0% {
    transform: translate(0,0) scale(1.1);
  }
  50% {
    transform: translate(25%,-30%) scale(.9);
  }
  100% {
    transform: translate(45%,-5%) scale(1.2);
  }
}
```

### React

```tsx
// @ts-nocheck
import { useEffect, useRef } from "react";

const css = `
.pt-mesh {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-mesh>* {
  opacity: var(--o);
}

.pt-mesh i {
  position: absolute;
  width: calc(90% * var(--d));
  aspect-ratio: 1;
  border-radius: 50%;
  -webkit-mask: radial-gradient(closest-side,#000,transparent);
  mask: radial-gradient(closest-side,#000,transparent);
  will-change: transform;
  animation: pt-mesh-a calc(20s / var(--k)) ease-in-out infinite alternate;
}

.pt-mesh i:nth-child(1) {
  background: var(--c1);
  left: -12%;
  top: -15%;
}

.pt-mesh i:nth-child(2) {
  background: var(--c2);
  right: -12%;
  top: 5%;
  animation-name: pt-mesh-b;
}

.pt-mesh i:nth-child(3) {
  background: var(--c3);
  left: 15%;
  bottom: -25%;
  animation-name: pt-mesh-c;
  animation-duration: calc(24s / var(--k));
}

.pt-mesh i:nth-child(4) {
  background: color-mix(in srgb,var(--c1),var(--c2));
  right: 5%;
  bottom: -15%;
  animation-direction: alternate-reverse;
}

.pt-mesh i:nth-child(5) {
  background: color-mix(in srgb,var(--c3) 70%,#fff);
  left: 38%;
  top: 28%;
  width: calc(34% * var(--d));
  animation-name: pt-mesh-b;
  animation-duration: calc(16s / var(--k));
}

@keyframes pt-mesh-a {
  0% {
    transform: translate(0,0) scale(1);
  }
  50% {
    transform: translate(30%,20%) scale(1.2);
  }
  100% {
    transform: translate(-10%,40%) scale(.9);
  }
}

@keyframes pt-mesh-b {
  0% {
    transform: translate(0,0) scale(1);
  }
  50% {
    transform: translate(-35%,25%) scale(.85);
  }
  100% {
    transform: translate(-10%,-20%) scale(1.15);
  }
}

@keyframes pt-mesh-c {
  0% {
    transform: translate(0,0) scale(1.1);
  }
  50% {
    transform: translate(25%,-30%) scale(.9);
  }
  100% {
    transform: translate(45%,-5%) scale(1.2);
  }
}

`;

export default function PatternMesh() {
  const ref = useRef(null);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-mesh"
        style={{
          "--c1": "#0071e3",
          "--c2": "#8b5cf6",
          "--c3": "#14b8a6",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <i></i><i></i><i></i><i></i><i></i>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Mesh gradient” block (Backgrounds) from AIMRAN Library to my project.

## What it is
Five soft blobs of color that melt into each other and drift slowly, like a living gradient.

## Chosen settings
- Color 1: #0071e3
- Color 2: #8b5cf6
- Color 3: #14b8a6
- Speed: 1x (from 0.2 to 3x)
- Density / scale: 1x (from 0.5 to 2x)
- Opacity: 1 (from 0.2 to 1)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck
import { useEffect, useRef } from "react";

const css = `
.pt-mesh {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-mesh>* {
  opacity: var(--o);
}

.pt-mesh i {
  position: absolute;
  width: calc(90% * var(--d));
  aspect-ratio: 1;
  border-radius: 50%;
  -webkit-mask: radial-gradient(closest-side,#000,transparent);
  mask: radial-gradient(closest-side,#000,transparent);
  will-change: transform;
  animation: pt-mesh-a calc(20s / var(--k)) ease-in-out infinite alternate;
}

.pt-mesh i:nth-child(1) {
  background: var(--c1);
  left: -12%;
  top: -15%;
}

.pt-mesh i:nth-child(2) {
  background: var(--c2);
  right: -12%;
  top: 5%;
  animation-name: pt-mesh-b;
}

.pt-mesh i:nth-child(3) {
  background: var(--c3);
  left: 15%;
  bottom: -25%;
  animation-name: pt-mesh-c;
  animation-duration: calc(24s / var(--k));
}

.pt-mesh i:nth-child(4) {
  background: color-mix(in srgb,var(--c1),var(--c2));
  right: 5%;
  bottom: -15%;
  animation-direction: alternate-reverse;
}

.pt-mesh i:nth-child(5) {
  background: color-mix(in srgb,var(--c3) 70%,#fff);
  left: 38%;
  top: 28%;
  width: calc(34% * var(--d));
  animation-name: pt-mesh-b;
  animation-duration: calc(16s / var(--k));
}

@keyframes pt-mesh-a {
  0% {
    transform: translate(0,0) scale(1);
  }
  50% {
    transform: translate(30%,20%) scale(1.2);
  }
  100% {
    transform: translate(-10%,40%) scale(.9);
  }
}

@keyframes pt-mesh-b {
  0% {
    transform: translate(0,0) scale(1);
  }
  50% {
    transform: translate(-35%,25%) scale(.85);
  }
  100% {
    transform: translate(-10%,-20%) scale(1.15);
  }
}

@keyframes pt-mesh-c {
  0% {
    transform: translate(0,0) scale(1.1);
  }
  50% {
    transform: translate(25%,-30%) scale(.9);
  }
  100% {
    transform: translate(45%,-5%) scale(1.2);
  }
}

`;

export default function PatternMesh() {
  const ref = useRef(null);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-mesh"
        style={{
          "--c1": "#0071e3",
          "--c2": "#8b5cf6",
          "--c3": "#14b8a6",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <i></i><i></i><i></i><i></i><i></i>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
