Text Highlight — <mv-text-highlight>

Highlights words as they enter the viewport: a marker stroke that sweeps across lines, or a hand-drawn annotation (underline, circle, box, strike-through) drawn stroke by stroke.

CategoryAnimated text
TypeWeb Component (<mv-text-highlight>)
Statusstable
Keywordshighlight, marker, underline, annotation, rough, hand-drawn, emphasis

When to use

Avoid when

Install

node scripts/add.mjs text-highlight --out ./src/marvelous

AI agent with the Marvelous UI MCP server: install_components({ slugs: ["text-highlight"], target_dir: "<absolute path>/src/marvelous", framework: "react" }).

Files copied (dependencies included): tokens/tokens.css, core/base.css, core/element.js, core/motion.js, core/observe.js, components/text-highlight/text-highlight.js, components/text-highlight/text-highlight.css.

Usage

Canonical markup — start from it and customize with attributes, data-* and CSS variables:

<div id="th-demo" style="display:grid;gap:1.75rem;max-width:40rem;text-align:center">
  <p style="margin:0;font:700 clamp(1.6rem,3.6vw,2.3rem)/1.35 var(--mv-font-sans);letter-spacing:-.025em">
    Your customers deserve answers <mv-text-highlight>in seconds</mv-text-highlight>,
    not <mv-text-highlight effect="strike" color="var(--mv-danger)" delay="700">in three days</mv-text-highlight>.
  </p>

  <p style="margin:0;font-size:1.125rem;line-height:1.9;color:var(--mv-fg-muted)">
    Centralize your tickets, <mv-text-highlight effect="underline" delay="200" style="color:var(--mv-fg)">automate replies</mv-text-highlight>
    to recurring questions and keep your team <mv-text-highlight effect="circle" color="var(--mv-warning)" delay="600" duration="1100" style="color:var(--mv-fg)">focused</mv-text-highlight>
    on what matters: <mv-text-highlight effect="box" color="var(--mv-info)" delay="1000" style="color:var(--mv-fg)">people</mv-text-highlight>.
  </p>

  <div style="display:flex;gap:1rem;justify-content:center;align-items:center;flex-wrap:wrap">
    <a href="#" style="font-weight:600;color:var(--mv-fg);text-decoration:none">
      <mv-text-highlight effect="underline" trigger="hover" duration="450">See pricing →</mv-text-highlight>
    </a>
    <button class="mv-button" data-variant="ghost" data-size="sm" id="th-replay">Replay</button>
  </div>
</div>
<script type="module">
  document.getElementById("th-replay")?.addEventListener("click", () => {
    document.querySelectorAll("#th-demo mv-text-highlight:not([trigger])").forEach((el) => el.replay());
  });
</script>

API

Attributes

NameTypeDefaultDescription
effectmarker | underline | circle | box | strikemarkerAnnotation style. SVG effects make the element inline-block (short phrases).
colorCSS colorvar(--mv-accent)Stroke / ink color (tokens accepted).
triggerview | load | hover | manualviewTrigger: entering the viewport (once), on load, on hover (of the parent link/button) or from script.
durationnumber800Draw duration (ms).
delaynumber0Delay before drawing (ms), to chain several annotations.

Methods

NameDescription
show()Draws the annotation.
hide()Erases the annotation (animated).
replay()Erases instantly, then redraws.

Events

NameDescription
mv-showWhen drawing starts.

CSS variables

NameDefaultDescription
--mv-text-highlight-colorvar(--mv-accent)Color (same as the color attribute).
--mv-text-highlight-markerMarker ink, if it should differ from the color (default: color at 28% / 45% in dark mode).
--mv-text-highlight-size78%Height of the marker stroke.
--mv-text-highlight-offset70%Vertical position of the marker.
--mv-text-highlight-stroke0.085emSVG stroke width.
--mv-text-highlight-easingvar(--mv-ease-in-out)Drawing easing curve.

Accessibility

The text is never modified; the SVG drawing is aria-hidden and ignores the pointer. To convey meaning (emphasis), wrap the content in <strong> or <mark>. Reduced motion: the annotation is shown right away, without drawing.