Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/gradient-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 Transition } from "motion/react";
import { cn } from "@/lib/utils";
import { usePageVisible, useReduceMotion, useTempoTransition } from "./motion";
const DEFAULT_GRADIENT =
"linear-gradient(90deg, #3b82f6 0%, #a855f7 20%, #ec4899 50%, #a855f7 80%, #3b82f6 100%)";
export type GradientTextProps = Omit<React.ComponentProps<"span">, "children"> & {
text: string;
gradient?: string;
neon?: boolean;
transition?: Transition;
};
export function GradientText({
text,
gradient = DEFAULT_GRADIENT,
neon = false,
transition,
className,
style,
...props
}: GradientTextProps) {
const ref = React.useRef<HTMLSpanElement>(null);
const inView = useInView(ref);
const pageVisible = usePageVisible();
const reduce = useReduceMotion();
const tween = useTempoTransition(
transition ?? { duration: 50, repeat: Infinity, ease: "linear" },
);
const playing = inView && pageVisible && !reduce;
const layer: React.CSSProperties = {
backgroundImage: gradient,
color: "transparent",
backgroundClip: "text",
WebkitBackgroundClip: "text",
backgroundSize: "700% 100%",
display: "inline-block",
};
return (
<span
ref={ref}
data-slot="gradient-text"
className={cn("relative inline-block", className)}
style={style}
{...props}
>
<motion.span
style={layer}
animate={playing ? { backgroundPosition: ["0% 0%", "500% 100%"] } : undefined}
transition={playing ? tween : undefined}
>
{text}
</motion.span>
{neon && (
<motion.span
aria-hidden="true"
style={{
...layer,
position: "absolute",
inset: 0,
mixBlendMode: "plus-lighter",
filter: "blur(8px)",
}}
animate={playing ? { backgroundPosition: ["0% 0%", "500% 100%"] } : undefined}
transition={playing ? tween : undefined}
>
{text}
</motion.span>
)}
</span>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/gradient-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 { GradientText } from "@/components/prequelui/gradient-text";
export default function Demo() {
return (
<GradientText
text="A gradient that keeps moving"
neon
className="text-4xl font-medium"
/>
);
}import { GradientText } from "@/components/prequelui/gradient-text";
export function Variant() {
return (
<GradientText tempo={1.2}>
…
</GradientText>
);
}Animation
The text is painted by a gradient three times wider than the word. The background position travels from the first stop to the far end over fifty seconds, so the colour drift is slow enough to read through.
- Loop: 50 s linear, background position 0% → 500%.
- The loop pauses when the element leaves the viewport or the tab is hidden.
- The neon layer repeats the gradient with an 8 px blur and plus-lighter blending.
- Reduced motion freezes the gradient at its first frame.
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.
GradientText
| Prop | Type | Default |
|---|---|---|
| text | string | — |
| gradient | string | blue → violet → pink |
| neon | boolean | false |
| transition | Transition | component spring or tween |
| className | string | — |