Skip to content

shadcn.io is an independent project built on shadcn/ui

Pro

Gradient Animation Background for Svelte

Soft blobs of color float on slow loops, blend and follow the pointer. For Svelte with Ark UI, when a hero needs moving color.

On this page10 sections
UI library: Ark UI

Large soft blobs of color float around the box on slow loops and blend where they overlap, and one more blob follows the pointer. It's a GLSL scene on WebGL2 with no dependency: each blob is a round falloff of one color, bent a little out of round, and overlapping colors are mixed in OKLab. The scene is transparent and reads the surface behind it, so it tints a light page and glows on a dark one, in a tone that keeps copy readable.

Use it behind a hero, a launch page or a pricing card. For one smooth field with no separate shapes, use Mesh Gradient; for bands of color that drift along an angle, Gradient; for drops that merge and split like liquid, Metaballs. With reduced motion it holds one still frame.

Playground
Gradient Animation Background, still
Customize

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

<script lang="ts">
import { GradientAnimation } from "@/components/ui/gradient-animation";
</script>
<GradientAnimation class="flex min-h-[32rem] items-center justify-center">
  <h1 class="text-5xl font-semibold">Brand colors your team can find</h1>
</GradientAnimation>

Gradient Animation is a container: whatever you put inside sits on top of the color, in normal flow. It fills its own box, so give it a height or content. For a backdrop behind the whole page, render it empty with className="fixed inset-0 -z-10".

Presets

Bloomthe default lookTry it
<GradientAnimation />
DuskTry it
<GradientAnimation
  blend={0.8}
  colors={["#ff6b4a", "#ffb03a", "#ff4d8d", "#7c3aed"]}
  count={4}
  intensity={1.4}
  pointerColor="#ffe08a"
  size={1.2}
  softness={0.95}
/>
<GradientAnimation
  blend={0}
  colors={["#4f46e5", "#0ea5e9", "#2dd4bf", "#a855f7"]}
  count={6}
  pointerColor="#f472b6"
  size={0.9}
  softness={0.1}
  warp={0.2}
/>
LagoonTry it
<GradientAnimation
  blend={0.25}
  colors={["#0ea5e9", "#14b8a6", "#6366f1"]}
  count={4}
  drift={1.4}
  pointerColor="#a7f3d0"
  size={1.1}
  softness={0.5}
/>
MistTry it
<GradientAnimation
  blend={1}
  colors={["#38bdf8", "#34d399", "#a78bfa"]}
  count={7}
  intensity={0.6}
  pointerColor="#f0abfc"
  size={1.3}
  softness={1}
  speed={0.6}
/>
MonoTry it
<GradientAnimation
  blend={1}
  colors={["var(--foreground)", "var(--muted-foreground)"]}
  pointerColor="var(--primary)"
  softness={1}
/>
NeonTry it
<GradientAnimation
  colors={["#00e5ff", "#7c4dff", "#ff2d95"]}
  grain={0.2}
  intensity={2}
  pointerColor="#c6ff3d"
/>

Each preset is a set of props, so copy one and keep tuning. Bloom is the default. Dusk melts four warm colors together and lets them run brighter for a dark page, Gel keeps every blob whole with a soft rim, like stacked color filters, Mist is the quiet one for a page with a lot of copy, and Mono takes its two colors from your theme.

Examples

Hero

The default look behind a centered hero. The blobs rest around the edges of the box, and across the middle band the color is held to a tone the foreground color reads on, so the headline needs no scrim. The chip and the second button have a translucent ground of their own.

Preview width

Colors

colors gives each blob its color in turn: here coral, amber, rose and plum on a dark surface, with count={4}, a wide softness and blend={0.8} so they melt into one field. intensity={1.4} lets the warm colors run brighter than the default tone, and pointerColor makes the blob on the pointer pale gold.

Preview width

In a card

Three blobs fill a small card: count={3} with size={1.2}, a cool palette and grain for a little texture. The copy sits at the bottom in the foreground color.

Preview width

Customization

Every color is a CSS color, so a theme variable works and follows a theme switch: colors={["var(--chart-1)", "var(--chart-2)"]}, pointerColor="var(--primary)". count, size and softness set how many blobs there are, how much of the box they cover and how much of each one is edge; blend runs from whole blobs with a seam between them to an even mix; drift and warp set how far they travel and how far they bend out of round.

The surface is the root's own background, bg-background by default. Give the root another (bg-slate-950, a brand color) and the scene adapts: it adds light to a dark surface and tints a light one. fade masks an edge, opacity turns the whole effect down, and grain adds film grain.

<GradientAnimation
  class="min-h-[32rem] bg-slate-950"
  colors={["var(--chart-1)", "var(--chart-2)", "var(--chart-4)"]}
  count={4}
  fade="bottom"
  grain={0.15}
  pointerColor="var(--chart-5)"
/>

Performance

It's one WebGL2 canvas and one fragment shader: two samples of simplex noise for the bend, then one falloff and one color conversion for each blob, twelve at most with the pointer's and the presses'. There's no blur filter and no blend mode for the browser to composite. It draws only while it's on screen and the tab is visible, shares one frame loop with every other background on the page, and lowers its own resolution if frames run long. quality sets the render scale yourself, and paused holds the frame.

Accessibility

The color is decoration: it's hidden from assistive tech and lets every click through to your content. With reduced motion it draws one still frame and ignores the pointer. Nothing flashes.

At intensity 1 or lower the color is held to a tone that copy in the foreground color (text-foreground) reads on. With the default palette the worst frame measured 6:1 on a light surface and 4.8:1 on a dark one across the middle of the box. Past intensity 1 the colors run brighter than that tone, so check your own copy or give it a ground.

FAQ

How do I change the colors?

Pass two to eight CSS colors to colors. Each blob takes the next one in turn, so with five blobs and four colors the first color shows twice. pointerColor is the blob on the pointer. Hex, oklch() and theme variables such as var(--chart-1) all work, and a variable follows your theme when it changes.

Does it work on a light page and a dark one?

Yes, with no prop to set. The scene reads the color behind it. On a light surface the blobs tint it and each color is lifted to a lighter tone; on a dark one they glow and each color is deepened. Set the surface with a class on the component, such as bg-slate-950.

How do I change or remove the blob that follows the pointer?

pointerColor sets its color and pointerSize its size, from 0 to 2; at 0 there's none. A press leaves a blob that swells and fades. interactive={false} turns off both. Touch never moves it, so scrolling on a phone isn't disturbed.

What does blend do?

It sets what happens where two blobs overlap. At 0 the nearer blob covers the farther one, so you see whole shapes with a soft seam between them. At 1 the two colors are averaged into one. Both are computed in OKLab, and the mix is given back the chroma its colors had, so pink over blue makes violet, not grey.

How do I put it behind the whole page?

Render it empty with className="fixed inset-0 -z-10". It still follows the pointer there, since it listens on the window. To put it behind one section, wrap that section's content in it and give it a height, such as min-h-svh.

Will it slow my page down?

It's a light shader: a dozen distance checks and color mixes a pixel, on the GPU, and nothing at all while it's off screen or the tab is hidden. There's no CSS blur, which is what makes the usual version of this effect heavy on large screens. If a device can't keep up, it renders fewer pixels by itself.

Does it work with Next.js and server components?

Yes. Import it into a server component and it renders its box and your content on the server; the canvas starts in the browser and fades in over the surface. It needs WebGL2, which every current browser has. Without it the box keeps its background, or the fallback you pass.

What happens with reduced motion?

It draws one still frame of the blobs and stops, and the pointer no longer adds one. The frame is the same every time, so the page looks the same on each visit. seed picks another layout of the same look.

API Reference

GradientAnimation

data-slot="gradient-animation"

PropType
blend?number

How far colors melt into each other where blobs overlap, from 0 (each blob keeps its own color up to a soft seam) to 1 (an even mix).

Default
0.5
colors?string[]

Two to eight CSS colors, one for each blob in turn. Theme variables such as var(--chart-1) follow your theme.

Default
["#2f6bff", "#a44bff", "#ff4d8d", "#1fc8e6"]
count?number

How many blobs float in the box, from 3 to 7.

Default
5
drift?number

How far each blob travels around its loop, from 0 (it holds its place) to 2.

Default
1
fade?"none" | "radial" | "top" | "bottom" | "left" | "right"

Which edges fade out to the surface: radial keeps the middle, the others name the side that fades.

Type
"none" | "radial" | "top" | "bottom" | "left" | "right"
Default
"none"
fallback?string

What shows until the first frame and in browsers without WebGL2: a CSS background value that looks like the scene.

grain?number

Film grain over the scene, from 0 to 1.

Default
0
intensity?number

How strongly the color shows, from 0 to 2. Up to 1 it stays in a tone copy reads on; past 1 the colors run at full brightness.

Default
1
interactive?boolean

Whether the scene follows the pointer and answers a press. Touch never moves it, so scrolling a page on a phone isn't disturbed.

Default
true
opacity?number

How strongly the scene shows over the surface, from 0 to 1.

Default
1
paused?boolean

Holds the current frame.

Default
false
pointerColor?string

The color of the blob that follows the pointer, as any CSS color.

Default
"#ff8a3d"
pointerSize?number

The size of the blob that follows the pointer, from 0 (none) to 2.

Default
1
quality?number

Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). Lower is cheaper and softer.

Default
1
seed?number

Another layout of the blobs and their loops, from 0 to 20.

Default
0
size?number

The size of the blobs, from 0.5 to 1.6. At 1 they cover most of the box between them, whatever the count.

Default
1
softness?number

How much of each blob is edge, from 0 (a disc with a soft rim) to 1 (it fades all the way from its center).

Default
0.8
speed?number

Animation speed: 1 is normal, 0 holds the frame.

Default
1
time?number

A fixed moment, in seconds: draws it and doesn't animate.

warp?number

How much the blobs bend out of round as they move, from 0 (circles) to 1.

Default
0.5