🚀 Ship faster with premium components 🚀
Search documentation v1.1.0

Stars

Render dynamic shooting stars on a canvas

Source Report Issue
Command docs
How to add this block to your project
npm run add Stars

Use the Stars component to create a visually engaging effect on your page with a canvas element:

Preview
Unlock code
How to use the Stars component in Astro
<Stars className="star" />

You can use the Stars component without any props. It’ll take up the available width of its container. By default, the component will render 25 shooting stars in a 45° angle. You can position it as a background using CSS positioning and z-index values. To target the canvas, pass a CSS selector using the className prop.

Density and Direction

You can change these default values using the density and directionDegree props:

Unlock code
How to change direction and number of stars
<Stars
density={8}
directionDegree={-45}
/>

By default, density is set to 5, which will render an 5x5 grid pattern. In the above example, increasing it to 8 will render an 8x8 grid, making the total number of stars 64. To better visualize emit locations, you can set the debug prop to true during development.

Size and Speed

Size and speed of the stars can also be configured using the size and speed props:

Size
Speed
Unlock code
How to customize size
<Stars size={4} />
Unlock code
How to customize speed
<Stars speed={2} />

API

Unlock code
Component API reference
type AnimateStarsProps = {
directionDegree?: number
size?: number
speed?: number
density?: number
padding?: number
randomized?: boolean
debug?: boolean
className?: string
}
PropDefaultPurpose
directionDegree 45 Sets the direction of the stars to a 45° angle by default.
size 1 Sets the size of the stars.
speed 1 Sets the animation speed of stars.
density 5 Sets grid density, where 5=5x5 grid pattern.
padding 1 Sets the area of the canvas to be used, where 1 equals to 100%.
randomized true Set to false for synchronized stars, true for randomized timing.
debug false Set to true to draw debug points for emit locations.
className - Pass additional CSS classes to the canvas.