Background

Gravity Stars

Stars pulled and pushed by an interactive gravity well.

gravity-stars.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/gravity-stars.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/gravity-stars.json

3

Turn on the motion

npx @prequelui/cli@latest animate gravity-stars

The CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

gravity-stars.tsx
import { GravityStarsBackground } from "@/components/prequelui/backgrounds/gravity-stars";

export default function Demo() {
  return (
    <div className="relative h-96 overflow-hidden rounded-xl">
      <GravityStarsBackground gravity="attract" />
    </div>
  );
}
import { GravityStars } from "@/components/prequelui/gravity-stars";

export function Variant() {
  return (
    <GravityStars tempo={1.2}>
      …
    </GravityStars>
  );
}

Animation

Eighty stars drift with a little noise and wrap around the edges. Inside a 110 px radius the pointer bends their velocity, brightens them and grows their glow; leaving the radius lets the same values settle back instead of resetting.

  • Influence radius: 110 px; strength: 80; mode attract or repel.
  • Glow follows the pointer distance and relaxes by 6% per frame.
  • Stars are culled per frame and wrapped, never recreated on move.
  • Reduced motion draws a still field with no velocity or glow.
80 starsradius 110attract / repelglow relax 6%

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

GravityStarsBackground

PropTypeDefault
interactivebooleantrue
starsCountnumber80
starsSizenumber2
starsOpacitynumber0.75
mouseInfluencenumber110
gravityStrengthnumber80
gravity"attract" | "repel""attract"
glowIntensitynumber14
starColorstring"#f8fafc"
speednumber1
pausedbooleanfalse
classNamestring—

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026