Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Free

Fog Background for React

Banks of soft mist that drift across a box at three depths, darkest at the edges. For React with Base UI, when a hero or a night scene needs atmosphere without pulling focus from its copy.

Framework

Banks of soft mist drift slowly across the box at three depths, each a little larger and faster than the one behind it, over a still glow near the floor, and the edges fade into the surface. Each bank is a strip of wisps, a noise texture the browser draws once from a small SVG, repeated sideways and slid by exactly one strip per loop, so the drift never jumps. The banks move with CSS transforms, which the browser composites without repainting: there's no blur filter and no script.

Use it for a moody hero, a night scene or a quiet launch card. For color instead of grey, use Mesh Gradient; for curtains of light, Aurora; for billowing plumes, Smoke; for weather that falls, Rain. With reduced motion the banks 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 { Fog } from "@/components/ui/fog";
<Fog className="flex min-h-[32rem] items-center justify-center">
  <h1 className="text-5xl font-semibold">Out of the mist</h1>
</Fog>

Fog is a container: whatever you put inside sits on top of the mist, 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

Color

fogColor takes any CSS color; here a pale blue. The surface is the root's own background, bg-background by default, and nothing in the fog depends on it, so bg-slate-950 (with the dark class, for dark-surface strength and text) keeps the scene dark in both color schemes.

Preview width

Low fog

fade="top" fades the mist out toward the top, so it lies low along the bottom of the card. fade also takes bottom, none, and radial, the default, which fades it toward every edge. The strips follow the box, so the wisps keep their shape at card size.

Preview width

Accessibility

The fog is decoration: it's hidden from assistive tech and lets every click through to your content. With reduced motion the banks stop where they are, and a still mist stays. Nothing flashes.

Put copy over it in your foreground color (text-foreground), the supporting lines too. At the default intensity the densest wisp behind the text keeps it above 5:1 in both color schemes; a muted color drops to about 2:1 on a dark surface. intensity="strong" brings body text on a dark surface down to about 3.5:1, so keep it for a headline and large text.

FAQ

How is the fog made?

Three banks of wisps drift at their own pace over a still glow near the floor. Each bank's wisps are an SVG noise texture the browser draws once and repeats sideways; the soft edges are in the texture and the gradients, not in a blur filter.

Can I tint it?

Yes. fogColor takes any CSS color, or set --fog-color in your CSS. By default it's your theme's text color, so the mist is pale on a dark surface and a grey haze on a light one.

How do I make it thicker or thinner?

intensity takes subtle, medium (the default) or strong. Light surfaces get a thinner version of each, so the haze never turns to smog.

Can I change the drift speed?

speed multiplies it: 2 is twice as fast, 0.5 half as fast. At 1 the farthest bank crosses one strip in three minutes and the nearest in about a minute and a half.

Will it slow my page down?

No. Three layers slide with translate, which the browser composites without repainting, and the noise is drawn once when the page loads. There's no blur filter and no JavaScript. The price is a few screens' worth of GPU memory, as for any animated layer wider than the screen.

Will text stay readable?

Use your foreground color for text over it. Muted grey text can fall below 4.5:1 over the densest wisps, and intensity="strong" is for headlines.

What happens with reduced motion?

The banks stop where they are, so the mist stays on screen as a still picture.

API Reference

Fog

<div> data-slot="fog"

PropType
fade?"none" | "radial" | "top" | "bottom"

Where the fog fades out: toward every edge, the top (fog lying low), the bottom, or nowhere.

Type
"none" | "radial" | "top" | "bottom"
Default
"radial"
fogColor?string

The mist's color, any CSS color.

Default
"var(--foreground)"
intensity?"subtle" | "medium" | "strong"

How thick the fog is: strong is for a headline only, since body text over it loses contrast.

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

How fast the banks drift: 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
--fog-colorstring

The mist's color (var(--foreground)).

--fog-speedstring

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

All 100 backgrounds