Components

Highlighter

A hand-drawn text highlighter for React and Tailwind CSS: a marker highlight, underline, circle, strike-through or box draws itself around inline text when it scrolls into view. Strokes are SVG paths measured from the text's own lines, so highlights and underlines wrap across line breaks, and several highlighters in a paragraph draw one after another.

  • 5 actions
  • Wraps across lines
  • Draws in sequence
  • Hand-drawn SVG
  • prefers-reduced-motion

DuskUI components are free to copy, built on shadcn/ui and animated with Motion.

Installation

$ npx shadcn@latest add https://duskui.com/r/highlighter.json

Usage

pitch.tsx
import { Highlighter } from "@/components/dusk/highlighter/highlighter"

export function Pitch() {
  return (
    <p>
      Set up in{" "}
      <Highlighter as="mark" action="highlight">
        under a minute
      </Highlighter>
      , no{" "}
      <Highlighter action="strike-through" color="#f87171">
        config files
      </Highlighter>
      .
    </p>
  )
}

Examples

Actions

action picks the annotation. Tune it with color, strokeWidth, iterations (pen passes), padding and duration.

  • highlightMarker highlight
  • underlineHand-drawn underline
  • circleCircled for emphasis
  • strike-throughStruck through
  • boxBoxed in

Across line breaks

Highlights and underlines get one stroke per visual line, drawn line after line, and redraw when the text rewraps.

Strokes are measured from the text's own line boxes, so a long highlight follows the sentence across every line break and an underline wraps just as neatly. Resize the window and they redraw.

API Reference

Also accepts any HTML attribute for the rendered element.

PropTypeDefaultDescription
childrenReactNode—Inline content to annotate. It can wrap across lines.
as"span" | "mark" | "strong" | "em" | "b" | "i""span"Element to render. mark suits highlights.
action"highlight" | "underline" | "circle" | "strike-through" | "box""highlight"How the annotation is drawn.
colorstringprimary (28% for highlight)Stroke color, any CSS color.
strokeWidthnumber2Line thickness in px. Ignored by highlight, which follows the text height.
iterationsnumber1 (highlight) / 2How many hand-drawn passes.
durationnumber0.9Seconds to draw the whole annotation, every line and pass.
delaynumber0Seconds to wait once its turn comes.
paddingnumber3Extra room around the text, in px.
sequencebooleantrueWait for highlighters that entered the view earlier, so they draw one after another.
seednumber—Change the hand-drawn wobble. Defaults to a hash of the text.

Accessibility

  • The text stays ordinary, selectable markup; the drawing is an aria-hidden SVG behind it (strike-through sits on top). Use as="mark" when the highlight carries meaning.
  • Nothing is drawn on the server and the wobble comes from a seeded generator inside effects, so there's no hydration mismatch.
  • Strokes are measured from the text's line boxes and redraw on resize and font load, so they never drift from the words.
  • With prefers-reduced-motion the annotation appears fully drawn, with no animation.