Back to TextsYou are on Highlight Text.

Highlight Text

A marker highlight that draws in behind the words.

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

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

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

Installation

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

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/highlight-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
highlight-text.tsx
"use client";

import * as React from "react";
import { motion, type HTMLMotionProps, type Transition } from "motion/react";
import { cn } from "@/lib/utils";
import {
  useReduceMotion,
  useSeen,
  useTempoTransition,
} from "./motion";

export type HighlightTextProps = Omit<HTMLMotionProps<"span">, "children"> & {
  text: string;
  delay?: number;
  color?: string;
  inView?: boolean;
  inViewOnce?: boolean;
  transition?: Transition;
};

export function HighlightText({
  text,
  delay = 0,
  color = "color-mix(in oklab, #f5c542 38%, transparent)",
  inView = false,
  inViewOnce = true,
  transition,
  className,
  style,
  ...props
}: HighlightTextProps) {
  const reduce = useReduceMotion();
  const ref = React.useRef<HTMLSpanElement>(null);
  const seen = useSeen(ref, inView, inViewOnce);
  const tween = useTempoTransition(
    transition ?? { duration: 2, ease: [0.42, 0, 0.58, 1] },
  );
  const shown = seen || reduce;
  const final = reduce ? { duration: 0 } : { ...tween, delay: (tween.delay ?? 0) + delay / 1000 };

  return (
    <motion.span
      ref={ref}
      data-slot="highlight-text"
      initial={reduce ? false : { backgroundSize: "0% 100%" }}
      animate={{ backgroundSize: shown ? "100% 100%" : "0% 100%" }}
      transition={shown ? final : { duration: 0 }}
      className={cn("relative inline-block", className)}
      style={{
        backgroundImage: `linear-gradient(${color}, ${color})`,
        backgroundRepeat: "no-repeat",
        backgroundPosition: "left center",
        ...style,
      }}
      {...props}
    >
      {text}
    </motion.span>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/highlight-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.

highlight-text.tsx
import { HighlightText } from "@/components/prequelui/highlight-text";

export default function Demo() {
  return (
    <p className="text-2xl">
      Motion should feel{" "}
      <HighlightText text="inevitable" delay={250} />.
    </p>
  );
}
import { HighlightText } from "@/components/prequelui/highlight-text";

export function Variant() {
  return (
    <HighlightText tempo={1.2}>
      …
    </HighlightText>
  );
}
03

Animation

The highlight is a background block clipped to the text box. It grows from zero width to full width behind the words, from the left, in two seconds; there is no separate element to misalign.

  • Background size: 0% 100% → 100% 100% over 2 s ease-in-out.
  • Delay is expressed in milliseconds and added to the transition delay.
  • The text never moves; only its background box changes size.
  • Reduced motion shows the final highlight immediately.
2 s ease-in-outbackground 0 → 100%left origindelay in ms
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.

HighlightText

PropTypeDefault
textstring—
delaynumber0
colorstringsoft amber
inViewbooleanfalse
inViewOncebooleantrue

Next component

Morphing Text

Letters glide to their new positions when the string changes.