Highlight Text

Text with a background that sweeps in from the left, like a highlighter.

Highlight Text
"use client"

import * as React from "react"
import { HighlightText } from "@animate-ui/react/primitives/texts/highlight"
import { RefreshIcon } from "@hugeicons/core-free-icons"
import { HugeiconsIcon } from "@hugeicons/react"

import { Button } from "@/components/ui/button"

export default function HighlightTextDemo({ delay = 0 }: { delay?: number }) {
  const [run, setRun] = React.useState(0)

  return (
    <div className="flex flex-col items-center gap-6">
      <HighlightText
        key={`${run}-${delay}`}
        delay={delay}
        className="rounded-md bg-linear-to-r from-blue-100 to-purple-100 px-1 text-4xl font-semibold dark:from-blue-500 dark:to-purple-500"
        text="Highlight Text"
      />
      <Button variant="outline" size="sm" onClick={() => setRun((n) => n + 1)}>
        <HugeiconsIcon icon={RefreshIcon} strokeWidth={2} data-icon="inline-start" />
        Replay
      </Button>
    </div>
  )
}

Installation

npm install @animate-ui/react motion
pnpm add @animate-ui/react motion
yarn add @animate-ui/react motion
bun add @animate-ui/react motion

Usage

The highlight is the element's background: give it one with your own classes.

import { HighlightText } from '@animate-ui/react/primitives/texts/highlight';

export function Title() {
  return (
    <HighlightText
      text="Highlight Text"
      className="bg-linear-to-r from-blue-100 to-purple-100"
      inView
    />
  );
}

Animation

  • The background grows from the left edge over 2s on an ease-in-out: slow at first, fastest midway, easing into place.
  • With inViewOnce={false}, it resets off screen and sweeps again on the next entrance.
  • <AnimateUIProvider tempo> paces the default duration.
  • Under reduced motion, the text is highlighted at once.

API Reference

HighlightText

PropTypeDefault
text
string-
delay?
number0
transition?
Transition{ duration: 2, ease: 'easeInOut' }
inView?
booleanfalse
inViewMargin?
string'0px'
inViewOnce?
booleantrue
...props?
Omit<HTMLMotionProps<'span'>, 'children'>-

Built by Skyleen. The source code is available on GitHub.

Last updated: 10/18/2026

On this page