Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/shimmering-text.jsonFirst component? Set up your project first
Frameworks
The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.
"use client";
import * as React from "react";
import { motion, useInView, type HTMLMotionProps } from "motion/react";
import { cn } from "@/lib/utils";
import {
splitGraphemes,
srOnlyStyle,
usePageVisible,
useReduceMotion,
useTempo,
} from "./motion";
export type ShimmeringTextProps = Omit<HTMLMotionProps<"span">, "children"> & {
text: string;
duration?: number;
wave?: boolean;
color?: string;
shimmeringColor?: string;
};
const REST = { x: 0, y: 0, scale: 1, rotateY: 0 };
const WAVE = {
x: [0, 5, 0],
y: [0, -5, 0],
scale: [1, 1.1, 1],
rotateY: [0, 15, 0],
};
export function ShimmeringText({
text,
duration = 1,
wave = false,
color = "var(--muted-foreground)",
shimmeringColor = "var(--foreground)",
className,
style,
...props
}: ShimmeringTextProps) {
const ref = React.useRef<HTMLSpanElement>(null);
const inView = useInView(ref);
const pageVisible = usePageVisible();
const reduce = useReduceMotion();
const tempo = useTempo();
const playing = inView && pageVisible && !reduce;
const chars = React.useMemo(() => splitGraphemes(text ?? ""), [text]);
const span = duration * tempo;
return (
<motion.span
ref={ref}
data-slot="shimmering-text"
className={cn("relative inline-block", className)}
style={
{
"--shimmer-color": shimmeringColor,
"--shimmer-base": color,
color,
perspective: "500px",
...style,
} as React.CSSProperties
}
{...props}
>
<span className="sr-only" style={srOnlyStyle()}>
{text}
</span>
<span aria-hidden="true" className="inline-block" style={{ perspective: "inherit" }}>
{chars.map((char, index) => (
<motion.span
key={`${char}-${index}`}
className="inline-block whitespace-pre"
style={{ transformStyle: "preserve-3d" }}
initial={{ ...(wave ? { scale: 1, rotateY: 0 } : {}), opacity: 1 }}
animate={
playing
? {
...(wave ? WAVE : {}),
opacity: [1, 0.35, 1],
}
: { ...(wave ? REST : {}), opacity: 1 }
}
transition={
playing
? {
duration: span,
repeat: Infinity,
repeatDelay: chars.length * 0.05,
delay: (index * span) / Math.max(1, chars.length),
ease: "easeInOut",
}
: { duration: 0 }
}
>
{char}
</motion.span>
))}
</span>
</motion.span>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/shimmering-text.jsonDependencies
motion lucide-reactThe registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.
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.
import { ShimmeringText } from "@/components/prequelui/shimmering-text";
export default function Demo() {
return (
<ShimmeringText
text="Shimmering"
duration={1}
wave
className="text-3xl font-medium"
/>
);
}import { ShimmeringText } from "@/components/prequelui/shimmering-text";
export function Variant() {
return (
<ShimmeringText tempo={1.2}>
…
</ShimmeringText>
);
}Animation
A band of light crosses the string letter by letter. Each letter follows the same opacity cycle with a delay proportional to its position, so the highlight travels instead of blinking; the wave option adds a small lift, scale and rotation.
- Opacity cycle: 1 s ease-in-out per letter, looping.
- Letter delay: index × duration ÷ letter count.
- Repeat delay after a full pass: letter count × 50 ms.
- Reduced motion holds the resting colour and no transform.
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.
ShimmeringText
| Prop | Type | Default |
|---|---|---|
| text | string | — |
| duration | number | 1 |
| wave | boolean | false |
| color | string | muted foreground |
| shimmeringColor | string | foreground |