Skip to content
Primitives

Gradient Text

Display type filled with the theme's gradient ramp, optionally panning on a loop.

Motionbackground-position pans one full period of a seamless ramp; static under reduced motion

Install

Install Kineto and follow the theme setup once in your app.

bash
npm install kineto
tsx
import { GradientText } from "kineto/gradient-text";

Preview

Ship something unmistakable

The ramp is the theme's own — recolor --gradient-from and every gradient in the system follows.

Static by default
tsx
"use client";

import * as React from "react";
import { motion, useReducedMotion, type HTMLMotionProps } from "motion/react";

import { cn } from "@/lib/cn";

/* Gradient-filled text, clipped to the glyphs. The static case is just the `text-gradient-brand`
 * utility — reach for this component when you want the ramp to move.
 *
 * Panning a two-stop gradient looks wrong: it slides to its end and snaps back. So the animated
 * mode swaps in `bg-gradient-brand-loop` (from → to → from at 200% width) and travels exactly one
 * period, landing where it started. Both modes read the same `--gradient-from` / `--gradient-to`
 * stops, so a themed gradient stays themed here.
 *
 * Renders a `<span>`; wrap it in whatever heading you need. Needs kineto's stylesheet for the
 * `bg-gradient-*` utilities (`@import "kineto/theme.css"`). */

export interface GradientTextProps extends HTMLMotionProps<"span"> {
  /** Pan the ramp across the text on a loop. Ignored under `prefers-reduced-motion`. */
  animated?: boolean;
  /** Seconds for one full pass of the animated ramp. */
  duration?: number;
}

const GradientText = React.forwardRef<HTMLSpanElement, GradientTextProps>(
  ({ className, animated = false, duration = 6, style, ...props }, ref) => {
    const reduced = useReducedMotion();
    const moving = animated && !reduced;

    return (
      <motion.span
        ref={ref}
        className={cn(
          // `inline-block` so the painted box wraps the glyphs rather than the whole line box;
          // the bottom padding keeps descenders out of the clip edge.
          "inline-block bg-clip-text pb-[0.05em] text-transparent",
          moving ? "bg-gradient-brand-loop" : "bg-gradient-brand",
          className
        )}
        style={style}
        animate={moving ? { backgroundPosition: ["0% 50%", "200% 50%"] } : undefined}
        transition={moving ? { duration, ease: "linear", repeat: Infinity } : undefined}
        {...props}
      />
    );
  }
);
GradientText.displayName = "GradientText";

export { GradientText };

src/components/ui/gradient-text.tsx

Props

PropTypeDefaultDescription
animatedbooleanfalsePan the ramp across the glyphs on a loop.
durationnumber6Seconds for one full pass.