# Diamond Sparkle

> Text that glitters like a cut stone under a spotlight: tiny four-point stars flare and fade across the letters, and the cursor showers a few more.

Category: Text · Free · Updated 2026-11-09 · Live demo: https://www.motionkitui.com/components/diamond-sparkle

## When to use it

Jewellery and engagement pages, beauty launches, celebrations and milestones, premium tiers and anywhere a headline should feel precious.

## How it works

A timer adds a sparkle at a random spot over the text several times a second, and moving the pointer adds more where it is, no more than one every 90 milliseconds. Each sparkle is a four-point star path with a soft drop-shadow glow. Motion scales it from nothing to full size and back while turning it a quarter turn, then removes it when the animation ends, so there are never more than a couple of dozen at once. The sparkles sit in an overlay hidden from screen readers, so the text is read as written.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/diamond-sparkle.json
```

Or copy `components/motionkit/diamond-sparkle.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | The text. |
| `colors` | `string[]` | `["#FFFFFF", "#FFF4D6", "#E4F1FF"]` | Colours the sparkles take. |
| `rate` | `number` | `6` | Sparkles per second. |
| `size` | `number` | `18` | Largest sparkle, in pixels. |
| `interactive` | `boolean` | `true` | Scatter extra sparkles where the pointer moves. |
| `as` | `ElementType` | `"span"` | Element to render, e.g. h1. |

## Accessibility

- **Keyboard: Not applicable.** Text, not a control.
- **Screen readers: Pass.** The sparkles are hidden from assistive tech; your text is read once, as written.
- **Reduced motion: Partial.** With reduced motion on, three still glints rest on the letters instead. Otherwise sparkles appear forever, so beside other content for more than 5 seconds WCAG 2.2.2 asks for a way to pause them.
- **Colour contrast: Pass.** The text keeps your colours; ivory on the site's dark measures 17:1.

## Source

```tsx
"use client";

import { useEffect, useRef, useState, type ElementType, type PointerEvent, type ReactNode } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";

type Sparkle = { id: number; x: number; y: number; size: number; color: string; turn: number };

type DiamondSparkleProps = {
  children: ReactNode;
  /** Colours the sparkles take; each picks one. */
  colors?: string[];
  /** Sparkles appearing per second. */
  rate?: number;
  /** Largest sparkle, in pixels. */
  size?: number;
  /** Scatter extra sparkles where the pointer moves. */
  interactive?: boolean;
  /** The element to render, e.g. "h1". */
  as?: ElementType;
  className?: string;
};

let next = 0;

/**
 * Text that glitters like a cut stone under a spotlight: tiny four-point stars flare and fade at random across the
 * letters, each one turning as it blooms. Run the pointer over the text and it showers a few more.
 */
export function DiamondSparkle({
  children,
  colors = ["#FFFFFF", "#FFF4D6", "#E4F1FF"],
  rate = 6,
  size = 18,
  interactive = true,
  as: Tag = "span",
  className = "",
}: DiamondSparkleProps) {
  const reduceMotion = useReducedMotion();
  const ref = useRef<HTMLElement>(null);
  const [sparkles, setSparkles] = useState<Sparkle[]>([]);
  const lastPointer = useRef(0);

  const make = (x: number, y: number): Sparkle => ({
    id: next++,
    x,
    y,
    size: size * (0.45 + Math.random() * 0.55),
    color: colors[Math.floor(Math.random() * colors.length)],
    turn: Math.random() > 0.5 ? 90 : -90,
  });

  // a steady trickle of sparkles at random places over the text
  useEffect(() => {
    if (reduceMotion || rate <= 0) return;
    const timer = window.setInterval(() => {
      setSparkles((current) => [...current.slice(-24), make(Math.random() * 100, 15 + Math.random() * 70)]);
    }, 1000 / rate);
    return () => window.clearInterval(timer);
    // make reads the latest colours and size each time it runs
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [reduceMotion, rate]);

  function move(event: PointerEvent) {
    if (!interactive || reduceMotion || event.pointerType === "touch") return;
    const now = performance.now();
    if (now - lastPointer.current < 90) return;
    lastPointer.current = now;
    const rect = ref.current!.getBoundingClientRect();
    const x = ((event.clientX - rect.left) / rect.width) * 100 + (Math.random() - 0.5) * 8;
    const y = ((event.clientY - rect.top) / rect.height) * 100 + (Math.random() - 0.5) * 30;
    setSparkles((current) => [...current.slice(-24), make(x, y)]);
  }

  // with reduced motion, a few still glints sit on the letters instead
  const still: Sparkle[] = reduceMotion
    ? [
        { id: -1, x: 12, y: 25, size: size * 0.8, color: colors[0], turn: 0 },
        { id: -2, x: 58, y: 70, size: size * 0.55, color: colors[1 % colors.length], turn: 0 },
        { id: -3, x: 88, y: 30, size: size * 0.65, color: colors[0], turn: 0 },
      ]
    : [];

  return (
    <Tag ref={ref} onPointerMove={move} className={`relative inline-block ${className}`}>
      <span aria-hidden className="pointer-events-none absolute inset-0 z-10 overflow-visible">
        {still.map((sparkle) => (
          <Star key={sparkle.id} sparkle={sparkle} />
        ))}
        <AnimatePresence>
          {sparkles.map((sparkle) => (
            <motion.span
              key={sparkle.id}
              className="absolute"
              style={{ left: `${sparkle.x}%`, top: `${sparkle.y}%` }}
              initial={{ scale: 0, rotate: 0, opacity: 1 }}
              animate={{ scale: [0, 1, 0], rotate: sparkle.turn, opacity: [1, 1, 0.6] }}
              transition={{ duration: 0.9, ease: "easeInOut" }}
              onAnimationComplete={() => setSparkles((current) => current.filter((item) => item.id !== sparkle.id))}
            >
              <Star sparkle={sparkle} />
            </motion.span>
          ))}
        </AnimatePresence>
      </span>
      <span className="relative">{children}</span>
    </Tag>
  );
}

// a four-point star with a soft glow, centred on its position
function Star({ sparkle }: { sparkle: Sparkle }) {
  const { size, color } = sparkle;
  return (
    <svg
      viewBox="0 0 24 24"
      width={size}
      height={size}
      className="absolute"
      style={{ left: sparkle.id < 0 ? `${sparkle.x}%` : undefined, top: sparkle.id < 0 ? `${sparkle.y}%` : undefined, transform: "translate(-50%, -50%)", filter: `drop-shadow(0 0 ${size / 4}px ${color})` }}
    >
      <path d="M12 0C12.6 7 17 11.4 24 12C17 12.6 12.6 17 12 24C11.4 17 7 12.6 0 12C7 11.4 11.4 7 12 0Z" fill={color} />
    </svg>
  );
}
```
