Share Gradient.js

Bring your designs to life with smooth, shared animated gradients

📦 Installation

npm install sharegradient

The lightweight, framework-agnostic engine for
high-performance shared & animated gradients.

🪶 Lightweight

Small runtime footprint. Zero dependencies. Built around the Canvas API and CSS custom properties.

⚡️ Responsive

One canvas source, one shared CSS variable, and adaptive updates for backgrounds, text, borders, and overlays.

🧩 Framework Free

Compatible with React, Vue, Svelte, or Vanilla. It just sets a CSS variable you use anywhere.

Overview

The hero sells the feeling. The rest explains the mechanism.

ShareGradient generates a gradient once, injects it as a CSS variable, and lets you reuse that same visual layer across your interface. The result is a more consistent design system with less duplicated CSS.

Output CSS variable

Use the generated image anywhere `background` is accepted.

Types Linear / Radial / Conic

Switch the gradient shape without changing your integration pattern.

Motion Static / Swirl / Rotate

Dial the amount of movement to match the component or the page.

Quick Start

Install, configure, start, reuse.

The public API stays intentionally small: build a controller, start it, then consume the CSS variable wherever you need it.

Install

Package

npm install sharegradient

The library is browser-focused and dependency-free at runtime.

Create one gradient

Minimal setup

import { createShareGradient } from "sharegradient";

const heroGradient = createShareGradient()
  .setColors([
    "#7c3aed",
    "#ec4899",
    "#f59e0b"
  ])
  .setCssVariable("--hero-gradient")
  .setAnimationMode("swirl")
  .setResolution(0.5)
  .build();

heroGradient.start();
01

Render once internally

The engine draws a gradient into a canvas and updates it at the rate you choose.

02

Inject a CSS custom property

The canvas snapshot becomes a `url(...)` stored in your target CSS variable.

03

Reuse everywhere

Backgrounds, text fills, borders, overlays, or animated offsets can all consume the same source.

Shared Usage

One generated source, multiple visual roles.

The point of the library is not just animation. It is reuse. A single gradient can become a page background, text treatment, border glow, and overlay tint without redefining the effect in every component.

Full background
Aa Text clip
Border effect
Overlay tint
CSS motion on top
JavaScript

Create the shared source

createShareGradient()
  .setColors([
    "#ff0f7b",
    "#f89b29",
    "#ff0f7b"
  ])
  .setCssVariable("--shared-grad")
  .setAnimationMode("swirl")
  .setFPS(24)
  .build()
  .start();
CSS

Consume it in multiple ways

.page {
  background: var(--shared-grad);
}

.title {
  background: var(--shared-grad);
  -webkit-background-clip: text;
  color: transparent;
}

.card::before {
  background: var(--shared-grad);
}
Examples

Shape and motion are independent knobs.

Keep the same mental model while changing the gradient type or the animation behavior. This is where the library becomes useful beyond hero backgrounds.

Linear + Swirl

Fluid hero and section backgrounds

createShareGradient()
  .setGradientType("linear")
  .setAnimationMode("swirl")
  .setCssVariable("--demo-linear")
Radial + Static

Spotlights, glows, focus areas

createShareGradient()
  .setGradientType("radial")
  .setOrigin(0.35, 0.4)
  .setAnimationMode("static")
  .setCssVariable("--demo-radial")
Conic + Rotate

Rings, loaders, rotating borders

createShareGradient()
  .setGradientType("conic")
  .setAnimationMode("rotate")
  .setRotationSpeed(0.04)
  .setCssVariable("--demo-conic")
API

Small surface area, enough control for real use.

The builder configures the output. The controller handles the lifecycle. Nothing more exotic than that.

Builder methods

Configuration

Method Purpose
setColors() Define gradient stops
setCssVariable() Choose the injected CSS variable
setGradientType() Switch between linear, radial, and conic
setAnimationMode() Use static, swirl, or rotate motion
setAngle() Set the angle for linear or conic rendering
setOrigin() Move the radial or conic center point
setFPS() Throttle updates with a familiar control
setResolution() Trade image sharpness against render cost
setQuality() Control output image compression quality
Controller methods

Lifecycle

start()

Initializes the engine, resizes the canvas, and begins the update loop.

pause()

Stops animation frames while keeping the last generated background in place.

resume()

Restarts a paused loop without rebuilding the full configuration.

once()

Renders a single frame for static pages or one-shot visual generation.

stop()

Stops the loop and clears the runtime listeners created by the controller.

const gradient = createShareGradient()
  .setColors(["#111827", "#6366f1"])
  .setCssVariable("--panel-grad")
  .build();

gradient.start();
gradient.pause();
gradient.resume();
gradient.stop();
Build With It

Use the same gradient system across hero banners, product cards, text treatments, and experimental UI.

ShareGradient is most useful when you want a single visual thread running through the whole interface instead of isolated CSS effects.