Skip to content
animorio
IT
Back to the library

Gradient editor

HoverGSAP, CSS onlyMediumCompressed weight: Demo 7.2 KBGSAP 28 KBFreeDownload the zip

A CSS gradient editor: three colour stops to drag along the bar, a dial for the angle and three ready gradients that blend into one another. The preview, its glow and the line of code rewrite themselves as you move, and a key copies it.

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>
<!--
  "Gradient editor" 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>Gradient editor</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>
  <main class="stage">
    <!-- a gradient editor: three colour stops slide along the bar, the dial turns the angle, the presets blend
         into one another, and the line of CSS below rewrites itself as you go -->
    <section class="ge" data-ge aria-label="Gradient editor">
      <header class="ge__head">
        <span class="ge__title">Gradient</span>
        <span class="ge__angle"><b data-deg>135</b><i>deg</i></span>
        <button class="ge__dial" type="button" data-dial aria-label="Angle" role="slider" aria-valuemin="0" aria-valuemax="360" aria-valuenow="135">
          <span class="ge__hand" data-hand></span>
        </button>
      </header>

      <div class="ge__view">
        <span class="ge__glow" data-glow aria-hidden="true"></span>
        <span class="ge__paint" data-paint aria-hidden="true"></span>
      </div>

      <div class="ge__bar" data-bar>
        <span class="ge__strip" data-strip aria-hidden="true"></span>
      </div>

      <div class="ge__presets" data-presets role="radiogroup" aria-label="Presets"></div>

      <div class="ge__code">
        <code data-code></code>
        <button class="ge__copy" type="button" data-copy aria-label="Copy CSS">
          <svg viewBox="0 0 20 20" aria-hidden="true"><g data-sheets><rect x="7" y="7" width="9" height="9" rx="2.200"></rect><path d="M4.200 12.600V6.200a2 2 0 0 1 2-2h6.400"></path></g><path class="ge__tick" data-tick pathLength="1" d="M5 10.400 8.600 14l6.600-7.800"></path></svg>
        </button>
      </div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </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.

15 values to change

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 “Gradient editor” 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

On near-black, a dark panel: at the top “Gradient”, the degrees and a small dial with its mark; below, the large preview of the gradient with a glow of its own colours; then the thin bar with the three stops (white tiles with the colour inside and the percentage below), the three ready gradients (Sunset, Aurora, Ember) and the line of CSS with its copy key. Dragging a stop, the tile lifts slightly and follows the finger a breath behind, never crossing its neighbours, and preview, bar, percentage and code change together. Turning the dial, the angle follows the direction of the finger. Choosing a ready gradient, the colours blend, the stops glide one after the other on a small spring and the mark takes the shortest way round. In the code each colour is written in its own colour; the copy key turns its two sheets into a tick being drawn.

How it works

The state in numbers

Each stop is an object with red, green, blue and position; the angle is a number. A single function writes from there two CSS variables (the gradient with its angle and the flat one for the bar), the handles and the line of code.

Dragging a breath behind

The pointer gives the percentage along the bar; the stop gets there with a tween of FOLLOW seconds, kept six points from its neighbours. The dial uses atan2 between its centre and the finger.

Blending two gradients

Choosing a preset, GSAP animates the three channels of each colour with power2.inOut and the positions with back.out, 0.06 s apart; the angle picks the shortest direction by adding or removing 360 degrees.

Values to change

NameFileDefaultWhat it changes
STARTscript.js0The gradient it opens with: 0 Sunset, 1 Aurora, 2 Ember.
BLENDscript.js0.9How many seconds one gradient takes to blend into the next.
FOLLOWscript.js0.16How far the stop lags behind the finger, in seconds (0 = glued).
GLOWscript.js0.55How strong the glow under the preview is, from 0 to 1.
HOLDscript.js1.5On its own: how many seconds it stops to look at each gradient.
LOOPscript.jstrueLeft alone, a pointer moves a stop, turns the angle, changes gradient and copies.

Try them in the Playground

When to use it

In the panel of a design tool, a site or theme builder, in settings where the background of a profile or a card is chosen, and on a gradient generator’s page.

On phones

The same piece: the stops have a 30-pixel touch area and are dragged by finger, the preview shrinks with the window’s height (a quarter of it) and the code wraps.

With reduced motion

No springs, lag or blending: stops, angle and ready gradients change at once.

Pitfalls

  • Colours blend in RGB, channel by channel: between two distant hues the middle can go grey. For cleaner blends, interpolate in OKLCH.
  • The stops and the dial are role sliders with keyboard arrows; a stop’s colour cannot be changed here: in a real editor each stop opens its own picker.
  • With zoom in the CSS, getBoundingClientRect sizes are in screen pixels: here they are only used as ratios, so they hold.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 17 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