Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Free

Gradient Background for React

Five soft color blobs that wander and overlap behind your content, under a fine film grain. For React with Base UI, when a hero or a launch section should feel colorful and alive without any interaction.

Framework

Five color blobs, teal, purple, blue, pink and violet, wander and overlap behind your content under a fine film grain, so the blends keep changing. Each blob is a radial gradient whose stops ease out to transparent, so it looks blurred without a blur filter. It sways on each axis at its own pace with CSS keyframes, so its path never quite repeats, and it moves with transforms, which the browser composites without repainting. Blobs are placed and sized from the component's box, not the window, so it works in a card as well as full screen. There's no script.

Use it when a hero should feel lively. For something calmer, with faint orbs that barely move, use Mesh Gradient; for something bigger, with very large fields that orbit and blend into new hues, Gradient Animation; for color in drifting bands, Aurora; for blobs that merge like a lava lamp, Metaballs. With reduced motion the blobs stand still.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Usage

import { Gradient } from "@/components/ui/gradient";
<Gradient className="flex min-h-[32rem] items-center justify-center">
  <h1 className="text-5xl font-semibold">Color that keeps moving</h1>
</Gradient>

Gradient 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".

Demos

Colors

colors takes up to five CSS colors, repeated when there are fewer; here amber, rose, orange, fuchsia and red. Theme variables such as var(--primary) work too.

Preview width

In a card

intensity="subtle" pales the blobs and grain={false} removes the grain. The blobs are sized from the box, so a card gets the whole composition, not a corner of it.

Preview width

Accessibility

The blobs are decoration: they're hidden from assistive tech and let every click through to your content. With reduced motion they stop where they are, and the colors stay as a still picture. Nothing flashes.

Put copy over it in your foreground color (text-foreground), the supporting lines too. Where the blobs overlap most it stays above 5:1 in both color schemes at the default intensity, but a muted color drops to about 2:1, which fails for text of any size.

FAQ

Which colors does it use?

Teal, purple, blue, pink and violet by default. Pass up to five CSS colors to colors, in any format, or set --gradient-color-1 to --gradient-color-5 in your CSS.

How do the blobs move?

Each blob sways sideways and up and down at two different paces, between 15 and 26 seconds a round trip, so its path never quite repeats and the overlaps keep changing. speed multiplies the pace: 2 is twice as fast.

What's the texture?

A still noise tile at low opacity, drawn once by the browser and repeated, so it stays fine at any size. It gives the gradients a film look and hides banding; grain={false} removes it.

How is it different from Mesh Gradient?

This one is brighter, its blobs roam the middle of the box and move in seconds, and its grain shows. Mesh Gradient's orbs are fainter, sit near the corners and take a minute or more per loop.

Can I put it in a card?

Yes. Blob sizes and positions follow the component's box, not the window, so a small card shows all five blobs.

Is it heavy?

No. Five gradient elements move with transforms, which the browser composites without repainting; there's no blur filter and no JavaScript.

What happens with reduced motion?

The blobs stop where they are, so the colors stay on screen as a still picture.

API Reference

Gradient

<div> data-slot="gradient"

PropType
colors?string[]

Up to five CSS colors for the blobs, repeated when there are fewer. By default teal, purple, blue, pink and violet.

grain?boolean

A fine film grain over the surface.

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

How strongly the blobs show over the surface.

Type
"subtle" | "medium" | "strong"
Default
"medium"
speed?number

How fast the blobs wander: 2 is twice as fast, 0.5 half as fast.

Default
1
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-color-1string

The first blob (teal).

--gradient-color-2string

The second blob (purple).

--gradient-color-3string

The third blob (blue).

--gradient-color-4string

The fourth blob (pink).

--gradient-color-5string

The fifth blob (violet).

--gradient-speedstring

The wander's speed, a multiplier (1).

--gradient-strengthstring

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

All 100 backgrounds