Components

Sparkles Text

A sparkling text effect for React and Tailwind CSS: small four-point stars pop in and out around a heading or a highlighted word. Positions come from a seeded generator, so they look random but are repeatable and never cause a hydration mismatch, and the text itself stays real, selectable and indexable.

  • SEO-friendly real text
  • Seeded, repeatable
  • No hydration mismatch
  • Pauses off-screen
  • prefers-reduced-motion

Your year in review

Installation

$ npx shadcn@latest add https://duskui.com/r/sparkles-text.json

Usage

hero-title.tsx
import { SparklesText } from "@/components/dusk/sparkles-text/sparkles-text"

export function HeroTitle() {
  return (
    <SparklesText as="h1" className="text-6xl font-bold">
      Magic, shipped
    </SparklesText>
  )
}

Examples

Colors

Pass any CSS colors in colors; each sparkle picks one. Change seed for a different (but stable) pattern.

Golden hour

Cool tones

Density & size

count sets how many sparkles are visible at once, size their pixel range and lifetime how long each one lives.

Sparse

count=2

Default

count=4

Busy

count=8

Inline highlight

Render it as strong or span to make one phrase in a sentence sparkle.

Every plan now includes unlimited projects and a custom domain, at no extra cost.

API Reference

Also accepts any HTML attribute for the rendered element.

PropTypeDefaultDescription
as"h1" … "h6" | "p" | "span" | "div" | "strong" | "em""span"Element to render. Use a heading level for titles.
colorsstring[]["rgb(255 255 255 / 0.8)", "rgb(255 255 255 / 0.5)"]Sparkle colors; each sparkle picks one.
countnumber4Sparkles visible at once.
size[number, number][6, 10]Sparkle size range in px.
lifetimenumber2Seconds each sparkle lives, from popping in to fading out.
seednumber7Seed for the generator. The same seed always plays the same sequence.
classNamestring—Font size, weight, color and other text styles.

Accessibility

  • The text is one real element with no duplicated copies, so it is selectable, translatable and read once by screen readers.
  • The sparkle layer is aria-hidden, ignores the pointer and cannot be selected.
  • Sparkles are generated in an effect, after hydration, so the server HTML is just the text.
  • The sparkle timer stops while the text is off-screen or the tab is hidden.
  • With prefers-reduced-motion the sparkles hold still instead of popping.