Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Pro

Gradient Animation Background for React

Very large, soft color fields that orbit slowly and blend into new hues, pastel on a light page and luminous on a dark one. For React with Base UI, when a hero, a launch or a portfolio page wants rich, moving color behind its copy.

Framework

Six very large, very soft fields of indigo, violet, sky, rose and purple orbit slow, off-center points over the whole box, overlapping so their hues blend into new ones: pastel on a near-white wash in light mode, luminous and added together on deep indigo in dark mode. Each field is one element the size of its gradient, whose stops ease out to transparent, so there's no edge anywhere and no blur filter; it turns about a point below its center while it sways, with CSS transforms, which the browser composites without repainting. A fine, still grain hides the banding soft gradients show on dark screens. There's no script unless you turn on the pointer field.

Use it behind a hero, a launch page or a portfolio. For the same idea as separate blobs on a plain surface, use Gradient; for calm color anchored in the corners, Mesh Gradient; for broad fields of color under a satin sheen, Silk; for color that merges like a lava lamp, Metaballs. With reduced motion the fields stand still.

Preview width

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

import { GradientAnimation } from "@/components/ui/gradient-animation";
<GradientAnimation className="flex min-h-[32rem] items-center justify-center">
  <h1 className="text-5xl font-semibold">Turn it up</h1>
</GradientAnimation>

Gradient Animation is a container: whatever you put inside sits on top of the color, in normal flow, in your foreground color. 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".

Demos

Colors

colors takes up to five CSS colors, repeated when there are fewer; here a dusk of coral, amber, rose, peach and plum. interactive adds one more soft field that glides after the mouse or pen, and pointerColor sets its color, here a warm amber.

Preview width

Calm

intensity="subtle" pales the fields and speed={0.5} halves the pace: a quieter version for a card. The fields are sized from the box's longer side, so they fill a card as they fill a page.

Preview width

Accessibility

The color is decoration: it's hidden from assistive tech and lets every click through to your content. The pointer field follows a mouse or pen only, so touch scrolling stays smooth, and it fades out where the pointer leaves. With reduced motion every field stops where it is, spread out as a still picture, and the pointer field is hidden. Nothing flashes, and the orbits take 27 to 44 seconds.

Put copy over it in your foreground color (text-foreground). At the default intensity it stays near 4.5:1 or above at the worst moment in both color schemes, in a page, a card or a phone hero; in a wide, short banner, where the fields crowd the middle, keep it to large text. intensity="strong" brings it lower, so keep small text off it there, and check again with your own colors.

FAQ

How do I change the colors?

colors takes up to five CSS colors in any format, theme variables too; fewer are repeated. You can also set --gradient-animation-color-1 to -5 in your CSS. The surface follows your theme's --background; backgroundColors takes two colors for it instead, as a 40° gradient, such as a deep purple to navy.

Does it follow light and dark mode?

Yes. In light mode the fields are pastel over a near-white wash of your background; in dark mode they're added together over a deep indigo, so where they overlap they glow. It's the same palette in both, tuned for each, with no invert filter.

How does the pointer field work?

With interactive, each mouse or pen move writes the pointer's position to two CSS variables on one more field, and a CSS transition makes it glide there. The first move lands at once, so it doesn't sweep in from a corner; when the pointer leaves, it fades out where it was. Touch doesn't move it. It's off by default.

Is it heavy?

No. Six fields turn and sway with rotate and translate, which the browser composites without repainting, and no script runs between pointer moves. There's no blur filter. The price is the fields' GPU memory, as for any animated layer the size of the screen, and it pauses offscreen.

How do I make it faster or slower?

speed multiplies the motion: 2 is twice as fast, 0.5 half as fast. At 1 each field orbits in 27 to 44 seconds and sways on its own, shorter period, so the colors keep meeting in new places.

What is the grain for?

Soft gradients band on many screens, dark ones most, and a fine, still film grain hides it. grain={false} leaves it out.

What happens with reduced motion?

The fields stop where they are, spread out as they are at first paint, and the pointer field is hidden.

API Reference

GradientAnimation

<div> data-slot="gradient-animation"

PropType
backgroundColors?[string, string]

The surface under the color: two CSS colors for a 40° linear gradient. By default a near-white wash in light mode and a deep indigo in dark mode, both mixed from your theme's --background.

colors?string[]

Up to five CSS colors for the fields, repeated when there are fewer. By default indigo, violet, sky, rose and purple.

Default
[]
grain?boolean

A fine, still film grain over the color, which hides the banding soft gradients show on dark screens.

Default
true
intensity?"subtle" | "medium" | "strong"

How strongly the fields show over the surface. Ark default: medium.

Type
"subtle" | "medium" | "strong"
Default
== undefined ? undefined : STRENGTH[intensity]
interactive?boolean

Whether one more soft field glides after the mouse or pen.

Default
false
pointerColor?string

The field that follows the pointer, any CSS color. By default the second color (violet).

speed?number

How fast the fields orbit: 2 is twice as fast, 0.5 half as fast. Ark default: 1.

Default
== undefined ? undefined : String(speed)
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

CSS variableType
--gradient-animation-color-1string

The first field (indigo).

--gradient-animation-color-2string

The second field (violet).

--gradient-animation-color-3string

The third field (sky).

--gradient-animation-color-4string

The fourth field (rose).

--gradient-animation-color-5string

The fifth field (purple).

--gradient-animation-fromstring

The surface's first color (theme-mixed).

--gradient-animation-pointerstring

The pointer's field (the second color).

--gradient-animation-speedstring

The orbits' speed, a multiplier (1).

--gradient-animation-strengthstring

The fields' strength, a multiplier of their alpha (1).

--gradient-animation-tostring

The surface's second color (theme-mixed).

All 100 backgrounds