Skip to content
animorio
IT
Back to the library

Mesh gradient background

Backgrounds, HoverGSAP, Canvas, CSS onlyMediumCompressed weight: Demo 7.1 KBGSAP 28 KBFreeDownload the zip

A background for a product’s hero made of a mesh gradient you can see and touch, as in the editor of a design tool: twelve points on a grid of hairlines, each with its own colour, breathing slowly on their own and dragged by the pointer on a spring, with the colour flowing along. The grid fades away when nobody touches it. Minimal style.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Mesh gradient background" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>The mesh gradient background with points to drag</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- the hero of an invented colour tool, Tinct, over a mesh gradient you can see and touch: a fine grid of curved
       lines through twelve control points, each carrying a colour; the points breathe on their own, follow the
       pointer on a spring when dragged, and the grid fades away when nobody touches it -->
  <main class="stage" data-stage>
    <canvas class="field" data-field aria-label="Mesh gradient: drag the points to move the colour" role="img"></canvas>
    <span class="grain" aria-hidden="true"></span>

    <section class="hero" aria-labelledby="hero-title">
      <p class="pill" data-in>
        <span class="pill__tag">New</span>
        <span class="pill__text">Mesh gradients in Tinct</span>
      </p>
      <h1 class="title" id="hero-title" data-in>Colour that<br>bends with you</h1>
      <p class="hint" data-in data-hint>
        <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 2.5v11M2.5 8h11M8 2.5 6.2 4.3M8 2.5l1.8 1.8M8 13.5l-1.8-1.8M8 13.5l1.8-1.8M2.5 8l1.8-1.8M2.5 8l1.8 1.8M13.5 8l-1.8-1.8M13.5 8l-1.8 1.8"></path></svg>
        <span>Drag the points</span>
        <button class="reset" type="button" data-reset>Reset</button>
      </p>
    </section>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

23 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Mesh gradient background” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

The first screen of an invented colour tool, Tinct: in the middle a pill «New · Mesh gradients in Tinct», the big two-line headline «Colour that bends with you» and below it «Drag the points» with a small Reset button. Behind it, across the whole page, a gradient of four close colours, mint, sky blue, lilac and apricot, born from twelve points on a four by three grid: each point carries its colour and the colours blend from one point to the next. At first the grid shows: hairline white lines running through the points and bending when they move, and the points, small white circles with a shadow and their colour in the middle, pop in one after the other with a bounce. Then, if nobody touches, the grid fades away and only the colour remains, breathing slowly as the points drift a little on their own. When the pointer passes, the grid comes back; the point under the pointer grows, and grabbed with the mouse or a finger it follows the hand on a spring with a hint of overshoot, with an orange ring around it, and the colour flows along. Let go, it stays where it was put; Reset sends every point back home, on a spring. If nobody touches, now and then a point drags itself, and after four moves the mesh tidies itself up.

How it works

Twelve points, one colour each

The points sit on a grid of four columns and three rows, in coordinates from 0 to 1, each with one of the four colours from :root. The middle columns are wide apart, so the points do not end up under the headline.

The colour of every pixel

The colour is painted on a small canvas, about 150 pixels across, then stretched over the whole page with high smoothing: for each pixel the average of the points’ colours weighted by a Gaussian of the distance (SOFTNESS), with a touch of light in the middle where the words sit. The blend is so soft that the stretch does not show, and it costs very little.

Lines that bend

For each row and column a Catmull-Rom curve, turned into Bézier curves, runs through the points: when a point moves the nearby lines bend with it. On top, the points: a white circle with a shadow and their colour in the middle.

The springs

Each point has a position and a velocity and chases its target with a spring (SPRING) and a damping that leaves a hint of bounce (BOUNCE). The target is where it was left plus the breath, two slow waves BREATH seconds long; while dragged it is the pointer.

The grid that fades

Every pointer move stamps the time; after GRID_FADE seconds of nothing the grid fades out slowly, and comes back quickly on the first pass. If nobody touches for AUTO_DRAG seconds, a GSAP timeline grabs a point and drags it on its own.

Values to change

NameFileDefaultWhat it changes
SOFTNESSscript.js0.22How far each point’s colour spreads.
BREATHscript.js6How many seconds one breath of the points lasts.
BREATH_AMPscript.js0.018How much the points move when they breathe (0 stops them).
SPRINGscript.js170How stiff the points’ spring is.
BOUNCEscript.js0.38How much the points bounce when they arrive.
GRID_FADEscript.js2.6After how many untouched seconds the grid fades away.
HANDLEscript.js6The radius of the points in pixels.
AUTO_DRAGscript.js2.2After how many untouched seconds a point drags itself (0 never).

Try them in the Playground

When to use it

As the background of the first screen of a design tool, a creative app, a product about colour or a launch: a gradient that invites play without stealing the scene from the headline.

On phones

The same mesh on a tall narrow page: the points are picked up with a finger, with a margin wider than the circle, and the page does not scroll while dragging them; the headline goes on two smaller lines.

With reduced motion

No breathing, no springs and no points moving on their own: the grid stays faint and visible, dragged points go straight where they are taken, the words are already in place.

Pitfalls

  • Painting every pixel at full resolution costs too much: the colour is computed on a small canvas and stretched, and the grain on top hides any banding.
  • Time comes from GSAP’s ticker and even the self-dragging point is a timeline: the preview bench controls everything and the video is always the same.
  • The canvas is resized on resize and with a ResizeObserver, because the demo window changes height while you watch; the points live in 0 to 1 coordinates and are never lost.
  • With touch-action: none on the page a finger drags the points instead of scrolling the page.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 7.1 KB; the libraries: GSAP 28 KB.

Testing

Tested on 23 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations