Stars Background

An interactive background featuring animated dots of varying sizes and speeds, simulating a dynamic and immersive starry space effect.

"use client"

import { useTheme } from "next-themes"

import { StarsBackground } from "@/components/animate-ui/backgrounds/stars"

export default function StarsBackgroundDemo() {
  const { resolvedTheme } = useTheme()

  return (
    <StarsBackground
      starColor={resolvedTheme === "dark" ? "#fff" : "#000"}
      className="absolute inset-0 bg-[radial-gradient(ellipse_at_bottom,#f5f5f5_0%,#fff_100%)] dark:bg-[radial-gradient(ellipse_at_bottom,#262626_0%,#000_100%)]"
    />
  )
}

Installation

npx shadcn@latest add @animate-ui/backgrounds-stars
pnpm dlx shadcn@latest add @animate-ui/backgrounds-stars
yarn dlx shadcn@latest add @animate-ui/backgrounds-stars
bun x shadcn@latest add @animate-ui/backgrounds-stars

Usage

import { StarsBackground } from '@/components/animate-ui/backgrounds/stars';

export function Hero() {
  return (
    <section className="relative h-[480px] overflow-hidden">
      <StarsBackground className="absolute inset-0" />
    </section>
  );
}

Animation

  • Three layers of stars (1, 2 and 3px) scroll upwards in a loop at different speeds, for depth: the smallest crosses 2000px in speed seconds, the others take two and three times longer. They move with hardware-accelerated transforms.
  • The sky shifts away from the mouse on a spring (factor, transition), relative to the center of the container, for parallax. On touch screens, a tap shifts it too.
  • The loops pause off screen and while the tab is hidden.
  • Under reduced motion, the stars hold still and there is no parallax.

API Reference

StarsBackground

PropTypeDefault
factor?
number0.05
speed?
number50
transition?
SpringOptions{ stiffness: 50, damping: 20 }
starColor?
string'#fff'
pointerEvents?
booleantrue
...props?
React.ComponentProps<'div'>-

Credits

Built by Skyleen. The source code is available on GitHub.

Last updated: 10/25/2026