Gravity Stars Background

A background component featuring an interactive gravity stars effect.

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

export default function GravityStarsBackgroundDemo() {
  return <GravityStarsBackground className="absolute inset-0" />
}

Installation

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

Usage

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

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

Animation

  • Stars drift across a canvas at movementSpeed, slow down little by little, wrap around its edges and glow.
  • Near the pointer (mouseInfluence), they are pulled in or pushed away (mouseGravity) and glow brighter. The pointer's last position keeps acting after it leaves (before the first move, it is the top-left corner).
  • The stars take the text color (currentColor), so they follow light and dark mode.
  • The canvas is sized to its container at the device pixel ratio. A resize scatters the stars again.
  • The simulation advances one step per displayed frame, so it runs faster on 120Hz screens.
  • It pauses off screen and while the tab is hidden.
  • Under reduced motion, the stars hold still.

API Reference

GravityStarsBackground

PropTypeDefault
starsCount?
number75
starsSize?
number2
starsOpacity?
number0.75
glowIntensity?
number15
glowAnimation?
'instant' | 'ease' | 'spring''ease'
movementSpeed?
number0.3
mouseInfluence?
number100
mouseGravity?
'attract' | 'repel''attract'
gravityStrength?
number75
starsInteraction?
booleanfalse
starsInteractionType?
'bounce' | 'merge''bounce'
...props?
React.ComponentProps<'div'>-

Credits

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

Last updated: 10/18/2026

On this page