Highlight Text

A marker highlight that draws in behind the words.

highlight-text.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/highlight-text.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/highlight-text.json

3

Turn on the motion

npx @prequelui/cli@latest animate highlight-text

The CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.

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>
  );
}

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

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

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026