Shooting stars streaking across a dotted sky at scattered times.
A slow-drifting night sky with twinkling stars, for space, launch and AI product heroes.
Customize
Usage
import { StarField } from "@/components/motionkit/star-field";
<StarField className="h-96 rounded-3xl">
<h1>Your hero</h1>
</StarField>Motion
The exact curves this component runs, plotted with Motion's own maths.
Drift
Runs on its own
Twinkle
Runs on its own
Space, launch and AI product heroes, night themes and "coming soon" pages.
Star positions come from an integer hash, so they match on the server and in every browser. Two stacked copies of the field scroll upward by exactly one copy's height, which loops seamlessly, and only about a third of the stars twinkle. That reads as natural and keeps the work small.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/star-field.jsonnpm install motionSave as components/motionkit/star-field.tsx.
"use client";
import type { ReactNode } from "react";
import { motion, useReducedMotion } from "motion/react";
type StarFieldProps = {
children?: ReactNode;
/** Number of stars. */
count?: number;
/** Seconds for the field to drift one full screen upward. */
duration?: number;
/** Star colour. */
color?: string;
className?: string;
};
// integer hash, so star positions match on server and client in every browser
function rand(seed: number) {
let t = Math.imul(seed ^ (seed >>> 15), 0x2c1b3c6d);
t = Math.imul(t ^ (t >>> 12), 0x297a2d39);
return ((t ^ (t >>> 15)) >>> 0) / 4294967296;
}
export function StarField({ children, count = 90, duration = 80, color = "#F6F1E8", className = "" }: StarFieldProps) {
const reduceMotion = useReducedMotion();
const stars = Array.from({ length: count }, (_, index) => ({
x: rand(index * 3 + 1) * 100,
y: rand(index * 3 + 2) * 100,
size: 1 + rand(index * 3 + 3) * 1.6,
// only about a third of the stars twinkle, which reads as natural and keeps the work small
twinkle: index % 3 === 0,
}));
return (
<div className={`relative isolate overflow-hidden bg-[#0C1010] ${className}`}>
{/* two stacked copies of the same field, scrolled by exactly one copy's height, loop seamlessly */}
<motion.div
aria-hidden
className="absolute inset-x-0 top-0 -z-10 h-[200%]"
animate={reduceMotion ? undefined : { y: ["0%", "-50%"] }}
transition={{ duration, repeat: Infinity, ease: "linear" }}
>
{[0, 50].map((offset) =>
stars.map((star, index) => (
<motion.span
key={`${offset}-${index}`}
className="absolute rounded-full"
style={{
left: `${star.x}%`,
top: `${offset + star.y / 2}%`,
width: star.size,
height: star.size,
backgroundColor: color,
opacity: 0.35 + (star.size - 1) * 0.3,
boxShadow: star.size > 2.2 ? `0 0 6px ${color}` : undefined,
}}
animate={!reduceMotion && star.twinkle ? { opacity: [0.2, 1, 0.2] } : undefined}
transition={{ duration: 2 + rand(index + 7) * 3, delay: rand(index + 11) * 4, repeat: Infinity, ease: "easeInOut" }}
/>
)),
)}
</motion.div>
{/* a faint glow at the bottom gives the field some depth */}
<div aria-hidden className="absolute inset-0 -z-10 bg-[radial-gradient(ellipse_at_bottom,rgb(14_124_134/0.18),transparent_60%)]" />
{children}
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| count | number | 90 | Number of stars. |
| duration | number | 80 | Seconds for the field to drift one full screen upward. |
| color | string | "#F6F1E8" | Star colour. |
| children | ReactNode | — | Content rendered above the effect. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/star-field.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
The sky holds still and stars stop twinkling for reduced-motion users. It loops forever otherwise, so if it sits beside other content for more than 5 seconds, WCAG 2.2.2 asks you to add a pause control.
Shooting stars streaking across a dotted sky at scattered times.
Drifting stars join into constellations as they pass close, and reach out to the cursor with lines of light.
A black hole with a glowing accretion disc: particles orbit faster near the centre, spiral inwards and pass behind the dark shadow.
Look up