Back to TextsYou are on Gradient Text.

Gradient Text

Text filled with a gradient that sweeps slowly across it.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
gradient-text.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/gradient-text.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/gradient-text.json
npmthe default on every machine

First 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.

5 runtimes
gradient-text.tsx
"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.json
npmthe default on every machine

Dependencies

motion lucide-react

The 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.

02

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.

gradient-text.tsx
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>
  );
}
03

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.
loop 50 slinear700% backgroundblur 8 px
04

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

PropTypeDefault
textstring—
gradientstringblue → violet → pink
neonbooleanfalse
transitionTransitioncomponent spring or tween
classNamestring—

Next component

Highlight Text

A marker highlight that draws in behind the words.