Text with small four-point sparkles that twinkle around it. The sparkles are drawn with CSS shapes and appear after the page loads.
Optional, and kept apart.
Nothing here is included in a project unless you add it, and the plain component it builds on is unchanged. This effect is decoration: it is hidden from screen readers, stands still for visitors who prefer reduced motion, and can be paused. Use Still on a preview to see that version.
import { SparklesText } from "@rdloom/react";
export default function SparklesTextBasicExample() {
return (
<div className="flex w-full justify-center py-6">
<SparklesText className="text-4xl font-bold">Something special</SparklesText>
</div>
);
}Installation
npx rdloom add sparkles-textCopies the source into src/components/rdloom. Edit it freely: rdloom upgrade merges later versions into your changes.
It also adds rdloom-motion.css next to your tokens and imports it from the tokens file, once: no setup, and no inline styles. The plain components you already use are untouched.
Use another registry client
npx shadcn@latest add https://rdloom.vimalbhatt.com/r/sparkles-text.jsonWorks, but without upgrade tracking, and you import the motion CSS yourself.
Usage
import { SparklesText } from "@rdloom/react";
<div className="flex w-full justify-center py-6">
<SparklesText className="text-4xl font-bold">Something special</SparklesText>
</div>Custom color
import { SparklesText } from "@rdloom/react";
export default function SparklesTextCustomColorExample() {
return (
<div className="flex w-full justify-center py-6">
<SparklesText count={12} color="#d97706" className="text-4xl font-bold">
Golden moments
</SparklesText>
</div>
);
}API Reference
Defined by the spec. Components also accept the props of the React Aria component they wrap.
| Prop | Type | Default |
|---|---|---|
childrenrequiredThe text. | string | none |
countHow many sparkles, from 1 to 20. | number | 8 |
colorColour of the sparkles, any CSS colour. | string | "var(--rd-color-action-primary)" |
isPausedStops the animation and shows the text plainly. Moving content that lasts more than five seconds should be stoppable. | boolean | false |
Accessibility
Role text, WCAG 2.2 AA. Tested with axe and keyboard tests; screen reader checks are in the audit checklist.
Keyboard
Not interactive.
Screen readers announce
- Read as ordinary text: the effect is purely visual
What your code must do
- The text is ordinary text in the page from the server render, readable with no JavaScript, and read once by screen readers
- Decoration only: the animated layers are hidden from assistive technology and never take focus
- Stands still for visitors who ask for less motion (prefers-reduced-motion), and can also be shown still with the rdm-still class or isPaused
- In forced-colors (high contrast) mode the text is drawn in the system colours with no effect
- Does not flash: nothing changes more than three times in a second (WCAG 2.3.1)
- Optional: it is a separate component, so projects that do not add it carry none of its code
- Choose a text colour with enough contrast on its own; the sparkles are small decoration and carry no meaning
Guidelines
Use it when
- One short heading or a highlighted word that should feel special
Avoid it when
- Body text or anything people read closely
- Several instances on one screen
Don't
- More than about 12 sparkles
- Sparkles carrying meaning, such as a status
Design tokens
The semantic tokens this component uses. Change them once and every component follows; see Design tokens.
--rd-color-text-default--rd-color-action-primary