Skip to content

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

Free

Fog Background for Vue

Layers of mist slide past at different depths around a low sun or moon. For Vue with Ark UI, when a hero needs atmosphere and calm.

On this page10 sections
UI library: Ark UI

Layers of mist slide sideways one behind the other, thick along the bottom of the box and thinning into wisps and gaps above it. It's a GLSL scene on WebGL2 with no dependency: each layer is a flat field of simplex noise that billows as it moves, far layers paler and slower, near ones denser and faster, around a low light. On a light surface it's grey-blue morning mist with a warm sun, on a dark one night mist under a cool moon, and the pointer clears a soft patch.

Use it behind a hero, a quiet launch section or a card that needs atmosphere. For curls that rise instead of banks that slide, use Smoke; for lit cumulus crossing a sky, Clouds; for ridgelines standing in haze, Dunes. With reduced motion it holds one still frame.

Playground
Fog Background, still
Customize

Installation

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

Usage

<script setup lang="ts">
import { Fog } from "@/components/ui/fog";
</script>
<template>
  <Fog class="flex min-h-[32rem] flex-col items-center pt-20">
    <h1 class="text-5xl font-semibold">Know the ridge before the weather does</h1>
  </Fog>
</template>

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

Presets

Morningthe default lookTry it
<Fog />
Ceilingthe default lookTry it
<Fog :detail="0.8" :height="0.5" placement="top" />
DuskTry it
<Fog
  :colors="['#f3c9b5', '#c69ab8', '#7b6aa3']"
  :light="1"
  lightColor="#ffb27a"
/>
MonoTry it
<Fog
  :colors="['var(--muted)', 'var(--muted-foreground)']"
  :density="0.8"
  :holes="0.7"
  :light="0"
/>
OrchidTry it
<Fog
  :colors="['#d8ccff', '#b49cf5', '#8463e0']"
  :light="0.9"
  lightColor="#ffb3d1"
/>
Valleythe default lookTry it
<Fog
  :density="1.4"
  :height="0.4"
  :holes="0.15"
  :layers="5"
  :light="0.7"
/>
Veilthe default lookTry it
<Fog
  :density="0.7"
  :holes="0.8"
  :layers="3"
  :light="0.3"
  placement="full"
  :scale="0.7"
/>

Each preset is a set of props, so copy one and keep tuning. Morning is the default. Valley packs a dense, low bank for the bottom of a hero or a footer, Veil spreads a thin mist over the whole box with placement="full", Ceiling hangs it from the top edge, and Mono takes its two colors from your theme.

Examples

Hero

The mist lies along the bottom edge and thins out by the middle of the box, so the copy sits at the top, where the surface is plain. No prop is set: the headline and the line under it use the foreground color, and the chip and the second button have a translucent ground of their own.

Preview width

Colors

colors runs from the farthest layer to the nearest and lightColor tints the mist around the low light: here apricot, rose and violet with an amber light at light={1}. A palette you pass is used on light and dark surfaces alike.

Preview width

In a card

height={0.7} lifts the mist most of the way up a small card and layers={3} keeps it plain at that size. The text sits at the top, above the bank.

Preview width

Customization

Every color is a CSS color, so a theme variable works and follows a theme switch: colors={["var(--muted)", "var(--muted-foreground)"]}. Without colors the scene picks its own palette from the surface, grey-blue mist with a peach sun on a light one and slate mist with a pale moon on a dark one. The layers are mixed in OKLab, so the light warms the mist without greying it.

The surface is the root's own background, bg-background by default. Give the root another (bg-slate-950, bg-stone-100) and the mist is painted over it, with the night palette when the surface is dark. placement picks the edge the bank lies along, fade masks an edge, opacity turns the whole effect down, and grain adds film grain.

<Fog
  className="min-h-[32rem] bg-slate-950"
  colors={["var(--chart-3)", "var(--chart-2)", "var(--chart-1)"]}
  grain={0.15}
  lightColor="var(--chart-4)"
  placement="top"
/>

Performance

It's one WebGL2 canvas and one fragment shader: two samples of value noise, four of simplex and one OKLab mix a layer, four layers by default and six at most, and a layer costs nothing above the height it reaches. There's no march and no simulation. 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. layers is the main cost, quality sets the render scale yourself, and paused holds the frame.

Accessibility

The mist 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.

Put copy above the bank, or use the foreground color (text-foreground) for every line on top of it. On a light surface the mist is darkest along the bottom edge, where foreground text still reaches 5.7:1, and it stays at 10:1 or better above the bottom fifth of the box. On a dark surface the top four fifths of the default look stay above 5:1, and the moonlit core of the bank, in the bottom fifth, drops to about 2:1: keep body copy off it, or lower light.

FAQ

How do I change the colors?

Pass two to eight CSS colors to colors. The first is the farthest layer and the last is the nearest, with the rest spread between, and lightColor sets the sun or moon that glows in the mist. Hex, oklch() and theme variables such as var(--muted-foreground) all work, and a variable follows your theme when it changes.

Does it work in dark mode and on a light page?

Yes, with no prop to set. The scene reads the color behind it and picks a palette: grey-blue morning mist with a peach sun on a light surface, slate night mist with a cool moon on a dark one. If you pass colors or lightColor, yours are used on both, so choose mid tones that read on white and on near-black, or pass theme variables.

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. For mist over the whole viewport and not only its lower part, add placement="full".

Will it slow my page down?

It costs at most 24 noise samples a pixel at the default four layers, fewer above the bank, all on the GPU, and nothing while it's off screen or the tab is hidden. If a device can't keep up, it renders fewer pixels by itself. On a phone-first page, layers={3} and quality={0.75} cut the work by about half, and soft mist hides the lower resolution well.

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.

How do I make the fog thicker or thinner?

density sets how opaque the mist is, from 0.3 to 1.6. holes opens soft gaps in it, from whole banks at 0 to separate patches at 1, and height sets how far up the box it reaches. For a heavy bank, raise density and lower holes; for a few thin wisps, do the opposite and drop layers to 2 or 3.

Can the fog hang from the top or cover the whole box?

placement="top" turns the scene over, so the bank hangs from the top edge like low cloud and the light sits up there with it. placement="full" veils the whole box evenly and ignores height. Over a full veil, keep density under 1 or put a translucent ground under body copy.

What happens with reduced motion?

It draws one still frame of the mist and stops, and the pointer no longer clears a patch. The frame is the same one every time, so the page looks the same on each visit. drift={0} is different: the layers stop sliding but still billow in place.

API Reference

Fog

data-slot="fog"

PropType
colors?string[]

Two to eight CSS colors for the mist, from the farthest layer to the nearest. Without it the scene picks its own: a pale morning mist on a light surface (the default below) and a moonlit night mist on a dark one.

Default
["#bfcce0", "#8ea4c2", "#5f789f"]
density?number

How thick the mist is, from 0.3 to 1.6.

Default
1
detail?number

How much fine wisp shows in the mist, from 0 (smooth banks) to 1.

Default
0.5
drift?number

How fast the layers slide sideways, from -2 to 2. Negative values slide the other way, and 0 leaves them billowing in place.

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
height?number

How far the mist reaches from its edge, as a share of the box, from 0.3 to 1.2. placement="full" ignores it.

Default
0.62
holes?number

How much the mist opens into soft gaps, from 0 (whole banks) to 1 (patches).

Default
0.5
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
layers?number

How many layers of mist slide one behind the other, from 2 to 6.

Default
4
light?number

How strongly a low sun or moon glows inside the mist, from 0 to 1.

Default
0.6
lightColor?string

The color of the light in the mist. Without it the scene uses a warm sunrise on a light surface (the default below) and a cool moon on a dark one.

Default
"#ffc4a8"
opacity?number

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

Default
1
paused?boolean

Holds the current frame.

Default
false
placement?"bottom" | "top" | "full"

The edge the mist lies along: bottom, top, or full to veil the whole box.

Type
"bottom" | "top" | "full"
Default
"bottom"
quality?number

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

Default
1
scale?number

The size of the banks, from 0.4 to 2: higher packs more, smaller ones into the box.

Default
1
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.