shadcn.io is an independent project built on shadcn/ui
Starfield Background for Vue
A night sky in depth: layers of stars drift and twinkle over soft haze. For Vue with Ark UI, when a hero needs a calm sky behind it.
On this page10 sections
Five layers of stars drift across the box at their own pace. They twinkle and vary in size, brightness and warmth, the brightest carry a thin cross of light, and slow clouds of haze sit behind them. It's a GLSL scene on WebGL2 with no dependency. The scene is transparent and reads the surface behind it, so the stars are light on a dark page and dark on a light one, and the layers lean with the pointer, near ones further than far ones.
Use it behind a hero, a launch page or a card that should feel like night; warp turns the drift into a slow flight through the stars. For streaks rushing out of a vanishing point, use Warp; for a quiet sky crossed now and then by one long trail, Shooting Stars; for clouds of glowing gas with stars in front, Nebula. With reduced motion it holds one still frame.


Installation
Usage
<script setup lang="ts">
import { Starfield } from "@/components/ui/starfield";
</script>
<template>
<Starfield class="flex min-h-[32rem] flex-col items-center justify-center">
<h1 class="text-5xl font-semibold">Know where every satellite is</h1>
</Starfield>
</template>
Starfield is a container: whatever you put inside sits on top of the sky, 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
<Starfield /><Starfield
:density="2.4"
:depth="1"
:glow="0.25"
:haze="0.8"
:hazeColors="['#7a3dff', '#d43d9b', '#2f6bff']"
:size="0.8"
:twinkle="0.3"
/><Starfield
:direction="90"
:haze="0.7"
:hazeColors="['#d857ff', '#5a5cff']"
:warmth="1"
/><Starfield
:density="3"
:glow="0"
:haze="0.5"
:hazeColors="['#19b8d8', '#2f6bff']"
:intensity="1.4"
:size="0.6"
:twinkle="0.9"
/><Starfield
:density="0.4"
:glow="0.8"
:haze="0.2"
:size="1.8"
:twinkle="0.3"
/><Starfield
:density="1.6"
:glow="0"
:haze="0"
:twinkle="0.2"
:warmth="0"
/><Starfield :density="1.3" :glow="0.9" :haze="0.25" :warp="1" />Each preset is a set of props, so copy one and keep tuning. Night is the default. Deep packs in more, smaller stars over thicker haze in three colors, Giants keeps a few large stars with long crosses, Warp flies through them, and Mono drops the haze and the tints so the sky is your foreground color only.
Examples
Hero
The whole sky is calm enough to sit under copy, so the hero is centered on it with no props set. The headline and the line under it use the foreground color; the chip and the second button have a translucent ground of their own, so a bright star passing behind them doesn't cut through the label.
In a card
Stars and spacing are sized in pixels, so a card shows fewer stars at the same density as a full page. Here hazeColors runs from orchid to indigo at haze={0.7}, warmth={1} brings out the blue and amber stars, and direction={90} drifts them upward.
Warp
warp={1} flies through the sky: each layer grows from the center, fades out as it passes and returns far away, so the flight never ends or jumps. The root has bg-slate-950, which the stars read as a dark surface in either theme, with density={1.3}, glow={0.9} and the haze down to 0.25.
Customization
color and hazeColors take any CSS color, so a theme variable works and follows a theme switch. The default color is var(--foreground): light stars in a dark theme, dark ones in a light theme. warmth adds blue and amber stars around that color, and 0 keeps them all alike. If color comes too close to the surface to show, such as the dark-theme foreground on a root you gave bg-white, the scene flips its lightness so the stars stay visible.
The surface is the root's own background, bg-background by default. Give the root another (bg-slate-950, a gradient) and the sky adapts: light adds to a dark surface and tints a light one. fade masks an edge, opacity turns the whole effect down, and grain adds film grain.
<Starfield
className="min-h-[32rem] bg-slate-950"
color="var(--chart-1)"
fade="bottom"
hazeColors={["var(--chart-2)", "var(--chart-4)"]}
warmth={0.3}
/>Performance
It's one WebGL2 canvas and one fragment shader. Each of the five layers is a grid with at most one star a cell, and a pixel looks at the four cells nearest to it, so it weighs 20 stars at most and skips the ones too far to reach it; the haze adds five samples of simplex noise. No loop grows with density: more stars means smaller cells, not more work. 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 sky 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: a star takes between 3 and 12 seconds to dim and come back.
Use the foreground color (text-foreground) for copy on top. Measured on the default frame, the mean contrast of foreground text is 17:1 on the default dark theme and 18:1 on the light one, and no 24-pixel block averages below 15:1, the thickest haze included. Only the cores of the stars fall under 4.5:1, under 0.1% of the pixels on either theme, each a few pixels wide. A star is the same color as the text, so a large one behind small print reads as a stray mark: lower size or glow under dense copy.
FAQ
How do I change the colors?
color sets the stars and hazeColors the clouds behind them, one to four colors that run from one cloud to the next. Both take hex, oklch() and theme variables such as var(--primary), and a variable follows your theme when it changes. warmth decides how many stars lean blue or amber around color.
Does it work on a light page?
Yes, with no prop to set. The default star color is your foreground color, so on a white page the stars are dark points and the haze is a pale tint, like a star chart. On a dark page the same scene adds light. Set the surface with a class on the component, such as bg-slate-950.
How do I make it fly through the stars?
Raise warp. At 0 the stars drift along direction; at 1 they stream out of the center of the box as each layer comes closer, fades and returns far away. Values between mix the two. It stays slow by design: for fast streaks, use the Warp background.
How do I get more stars, or fewer and larger ones?
density multiplies how many there are: 2 packs twice as many into the same box, 0.4 leaves a sparse sky. size scales every star, and glow sets how much of a halo and a cross the brightest carry. A dense sky of small stars with glow={0} reads as dust; a sparse one with size={1.8} reads as a few close stars.
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: 20 stars and five noise samples a pixel at most, on the GPU, and nothing at all while it's off screen or the tab is hidden. If a device can't keep up, it renders fewer pixels by itself. For a phone-first page, quality={0.75} draws a little over half the pixels; the smallest stars soften first.
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.
API Reference
Starfield
data-slot="starfield"
color?string
The stars' color, any CSS color. The default follows your theme: light stars on a dark surface, dark ones on a light surface.
- Default
"var(--foreground)"
density?number
How many stars there are: 1 is the designed sky, 2 packs twice as many into the same box.
- Default
1
depth?number
How far apart the layers feel, from 0 (a flat sky that moves as one) to 1 (near stars pass far ones, and lean further with the pointer).
- Default
0.7
direction?number
The way the stars drift, in degrees: 0 is to the right, 90 up, 180 to the left, -90 down.
- Default
160
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.
glow?number
How much of a halo and how long a cross of light the brightest stars carry, from 0 to 1.
- Default
0.5
grain?number
Film grain over the scene, from 0 to 1.
- Default
0
haze?number
How strongly the clouds of haze behind the stars show, from 0 to 1.
- Default
0.5
hazeColors?string[]
One to four CSS colors the haze runs through, from one cloud to the next.
- Default
["#5a4dff", "#1f8fff"]
intensity?number
How bright the stars and the haze are.
- 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
quality?number
Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). Lower is cheaper and softer.
- Default
1
size?number
The stars' size, as a multiplier: 1 keeps the smallest about a pixel wide.
- 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.
twinkle?number
How much the stars twinkle, from 0 (steady) to 1.
- Default
0.5
warmth?number
How much the stars vary in color, from 0 (all color) to 1 (blue and
amber ones among them).
- Default
0.6
warp?number
How much you fly through the stars instead of watching them drift, from 0 (a drifting sky) to 1 (stars stream out of the center).
- Default
0











