Gradient

An animated gradient that flows like liquid: glass ribbons with colour-split edges, soft folds of silk, a glow through reeded glass, colour woven into cloth, a beam of light pinched to a point, a glow of heat in thermal colours, or a mesh of drifting colour. The pointer stirs it; the library's dither finishes it.

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/gradient.json

This copies the component into components/fabricui and its engine into lib/fabricui. It's your code from then on. First time? Add the theme once: see Installation.

Code

components/fabricui/gradient.tsx
"use client";

import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { GradientEngine } from "@/lib/fabricui/gradient-engine";
import "./gradient.css";

const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;

export type GradientVariant = "glass" | "silk" | "fluted" | "weave" | "beam" | "thermal" | "mesh";

/** Ready-made colours for `colors`, deep to light. Blue is the default. */
export const GRADIENT_COLORS = {
  blue: ["#0b2a5e", "#2f74d6", "#bfe0ff"],
  violet: ["#2a0b5e", "#7b45e6", "#e2ccff"],
  rose: ["#4a0626", "#e0457b", "#ffd0e2"],
components/fabricui/gradient.css
/*
 * gradient.css — Gradient (gradient-engine.js). The gradient is drawn on the
 * canvas behind the element's content; size the element and put anything in it.
 */
.grad:where(.fui-gradient, .fui-gradient *) {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: #010205;   /* until the first frame, and without WebGL */
  color: #f3f8ff;
}
.grad__canvas:where(.fui-gradient, .fui-gradient *) {
  position: absolute;
  inset: 0;
  z-index: -1;
  display: block;
lib/fabricui/gradient-engine.js
/*
 * gradient-engine.js — Gradient: an animated gradient that flows like liquid,
 * drawn in a WebGL shader and finished with the library's ordered dither.
 *
 *   const g = new GradientEngine(root, { variant: "glass" });
 *   g.set({ variant: "silk", speed: 0.6, dither: 0.8 });
 *   g.destroy();
 *
 * Two looks, the same flow under both (a sine field bent through itself a few
 * times, so it folds and curls without ever repeating):
 *   glass — thin liquid-glass ribbons over a dark, soft glow: a bright rim
 *           where each ribbon turns away, split into colour at its edge, and
 *           the glow behind bent through it.
 *   silk  — broad soft folds of satin: lit from above-left, with a sheen
 *           along the crests and black in the valleys.
 *   fluted — soft pools of colour seen through reeded glass: upright flutes,

Usage

Usage
"use client";

import { Gradient, GRADIENT_COLORS } from "@/components/fabricui/gradient";

export function Hero() {
  return (
    <Gradient variant="glass" style={{ height: 480, borderRadius: 24 }}>
      <h1 style={{ padding: 48 }}>Made of fabric</h1>
    </Gradient>
  );
}

// soft silk, slower, in a ready-made colour, in coarse dots
export function Banner() {
  return <Gradient variant="silk" speed={0.6} dither={1} colors={GRADIENT_COLORS.violet} style={{ height: 240 }} />;
}

// or your own colours, deep to light
export function Card() {
  return <Gradient variant="glass" colors={["#3b0a45", "#a43ad6", "#f4c6ff"]} style={{ height: 200, borderRadius: 20 }} />;
}

Props

PropTypeDefault
variant

glass: liquid-glass ribbons with bright, colour-split rims over a dark glow. silk: soft satin folds with a sheen on the crests. fluted: soft pools of colour seen through reeded glass, each flute squeezing and shearing the glow behind it. weave: the gradient woven into twill cloth, round threads in diagonal ribs, shimmering two-tone as the colour moves. beam: the gradient as light pouring in from the left between two great black curves, pinched to a point that runs on to the right as a thin line; pulses of colour pump along the line and through the point, swelling out to the left, each a slightly different hue, while neighbouring hues swirl and mix through the beam; rays sway and the curved edges catch a tinted light; with prism, white light pumps along the line and splits through the point into colour. In light mode it's drawn on white, fading in from white and deepening to the point; the pointer stirs the rays and nudges the point. thermal: heat filling the whole frame, cold at the top and hot at the base, blended with no edges at all, in a heat map from your deep and mid colours through lavender to orange and red (your colours turned round the hue wheel); slow plumes of heat rise through it, the bands drift and waver gently, its sides run a little cooler, and the pointer warms where it moves. mesh: five pools of colour, your deep, mid and light and your mid turned toward violet and toward teal (or five colours of your own), each drifting on its own slow loop and blending smoothly edge to edge across the frame; the pointer stirs them.

"glass" | "silk" | "fluted" | "weave" | "beam" | "thermal" | "mesh""glass"
prism

Beam only: white light pumps along the thin line and, as through a prism, splits at the point into sky blue, hot pink, orange and cream fanned across the beam, each blended smoothly into the next, its colours sliding as the light streams.

booleanfalse
speed

How fast it flows.

number1
dither

The library's ordered dither: 0 is smooth (just enough grain to stop banding), 1 is coarse dots.

number0.3
interactive

The flow swirls round the pointer as it moves and settles when it stops.

booleantrue
paused

Hold it still. It also pauses off-screen and in a hidden tab, and holds still with reduced motion.

booleanfalse
colors

Your own colours, deep to light (one to three), or a preset: GRADIENT_COLORS.blue, violet, rose, ember, mint or mono. Mesh takes up to five, one for each of its pools, in your order. Changing them blends. Default: the theme's blues, on near-black or white.

string[]—
children

Content to sit on it; the gradient is drawn behind.

ReactNode—