Marker highlight
Inline emphasis that gets drawn in as the reader reaches it: a highlighter swipe, a thick underline, or a hand-drawn loop around a short phrase.
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type ReactNode,
} from "react";
import "./mark.css";
type MarkProps = {
children: ReactNode;
/** marker: a highlighter swipe. underline: a thick pen line. circle: a hand-drawn loop (short words only). */
variant?: "marker" | "underline" | "circle";
/** Any CSS color. */
color?: string;
/** Milliseconds to wait after the text comes into view. */
delay?: number;
};
/**
* Mark
* Inline emphasis that gets drawn in, like a pen on paper, once the reader
* reaches it. The words are always there; only the ink animates.
*/
export function Mark({
children,
variant = "marker",
color = "#ff5a1f",
delay = 0,
}: MarkProps) {
const ref = useRef<HTMLElement>(null);
const [on, setOn] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const io = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setOn(true);
io.disconnect();
}
},
{ threshold: 1 },
);
io.observe(el);
return () => io.disconnect();
}, []);
const style = {
"--gu-mark-color": color,
"--gu-mark-delay": `${delay}ms`,
} as CSSProperties;
return (
<mark
ref={ref}
className={`gu-mark gu-mark--${variant}`}
data-on={on}
style={style}
>
{children}
{variant === "circle" && (
// A loop that overshoots its start, the way a real pen stroke does.
<svg
className="gu-mark__loop"
viewBox="0 0 200 80"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
pathLength={1}
d="M150 8C108 0 30 6 10 32c-14 20 18 40 82 42 64 2 106-14 102-36C190 14 136 6 70 14"
/>
</svg>
)}
</mark>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Marker highlight
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
Inline emphasis that gets drawn in, like a pen on paper, once the reader reaches it. Three styles: a highlighter swipe, a thick underline, and a hand-drawn loop around a short phrase. The words never move; only the ink animates.
## Behavior and motion
- Uses a <mark> element. An IntersectionObserver with threshold 1 starts the drawing when the whole phrase is on screen (once).
- marker: background-size goes from 0% to 100% width (height 72%, positioned at 58%) over 0.9s, cubic-bezier(0.65, 0, 0.35, 1). The gradient runs at 100deg with slightly ragged, semi-transparent ends so it reads as a real highlighter. box-decoration-break: clone, so every wrapped line gets its own stroke.
- underline: a 0.14em line at 92% height grows from the left the same way.
- circle: the phrase becomes inline-block (nowrap) and an SVG loop drawn with pathLength=1 animates stroke-dashoffset 1 → 0 over 1.1s. The path overshoots its start like a real pen stroke. Stroke 3.5px, round caps, vector-effect: non-scaling-stroke.
- `delay` (ms) staggers several marks in one paragraph.
## Look
Inherits font and color. Demo: one serif sentence at up to 2.4rem: orange marker (ultramarine #2b35ff in dark mode so cream text stays readable), ultramarine underline (lime #d7ff3a in dark mode), and an orange loop around "worth it". A "Draw again" outline button replays it.
## Accessibility
- <mark> tells screen readers the text is highlighted. The loop SVG is aria-hidden.
- forced-colors: a 1px outline replaces the ink.
- prefers-reduced-motion: the ink is simply there. Nothing draws.
## Props
children, variant ("marker" | "underline" | "circle"), color (any CSS color), delay (ms).
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### Mark.tsx
```tsx
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type ReactNode,
} from "react";
import "./mark.css";
type MarkProps = {
children: ReactNode;
/** marker: a highlighter swipe. underline: a thick pen line. circle: a hand-drawn loop (short words only). */
variant?: "marker" | "underline" | "circle";
/** Any CSS color. */
color?: string;
/** Milliseconds to wait after the text comes into view. */
delay?: number;
};
/**
* Mark
* Inline emphasis that gets drawn in, like a pen on paper, once the reader
* reaches it. The words are always there; only the ink animates.
*/
export function Mark({
children,
variant = "marker",
color = "#ff5a1f",
delay = 0,
}: MarkProps) {
const ref = useRef<HTMLElement>(null);
const [on, setOn] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const io = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setOn(true);
io.disconnect();
}
},
{ threshold: 1 },
);
io.observe(el);
return () => io.disconnect();
}, []);
const style = {
"--gu-mark-color": color,
"--gu-mark-delay": `${delay}ms`,
} as CSSProperties;
return (
<mark
ref={ref}
className={`gu-mark gu-mark--${variant}`}
data-on={on}
style={style}
>
{children}
{variant === "circle" && (
// A loop that overshoots its start, the way a real pen stroke does.
<svg
className="gu-mark__loop"
viewBox="0 0 200 80"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
pathLength={1}
d="M150 8C108 0 30 6 10 32c-14 20 18 40 82 42 64 2 106-14 102-36C190 14 136 6 70 14"
/>
</svg>
)}
</mark>
);
}
```
### mark.css
```css
.gu-mark {
--gu-mark-ease: cubic-bezier(0.65, 0, 0.35, 1);
background: none;
color: inherit;
padding: 0 0.08em;
margin: 0 -0.08em;
/* Each wrapped line gets its own stroke, with its own rounded ends. */
-webkit-box-decoration-break: clone;
box-decoration-break: clone;
background-repeat: no-repeat;
transition: background-size 0.9s var(--gu-mark-ease);
transition-delay: var(--gu-mark-delay, 0ms);
}
/* Highlighter: slightly ragged ends and a band that misses the line's top and bottom. */
.gu-mark--marker {
background-image: linear-gradient(
100deg,
transparent 0.6%,
color-mix(in srgb, var(--gu-mark-color) 78%, transparent) 2%,
color-mix(in srgb, var(--gu-mark-color) 62%, transparent) 50%,
color-mix(in srgb, var(--gu-mark-color) 80%, transparent) 97%,
transparent 99.4%
);
background-position: 0 58%;
background-size: 0% 72%;
border-radius: 0.3em 0.12em 0.4em 0.15em;
}
.gu-mark--marker[data-on="true"] {
background-size: 100% 72%;
}
/* Underline: a thick line that sits low, under the descenders' baseline. */
.gu-mark--underline {
background-image: linear-gradient(var(--gu-mark-color), var(--gu-mark-color));
background-position: 0 92%;
background-size: 0% 0.14em;
}
.gu-mark--underline[data-on="true"] {
background-size: 100% 0.14em;
}
/* Circle: one line only, so the loop can wrap the whole phrase. */
.gu-mark--circle {
position: relative;
display: inline-block;
white-space: nowrap;
}
.gu-mark__loop {
position: absolute;
inset: -0.35em -0.4em -0.3em -0.45em;
width: calc(100% + 0.85em);
height: calc(100% + 0.65em);
overflow: visible;
pointer-events: none;
}
.gu-mark__loop path {
fill: none;
stroke: var(--gu-mark-color);
stroke-width: 3.5;
stroke-linecap: round;
vector-effect: non-scaling-stroke;
stroke-dasharray: 1;
stroke-dashoffset: 1;
transition: stroke-dashoffset 1.1s var(--gu-mark-ease);
transition-delay: var(--gu-mark-delay, 0ms);
}
.gu-mark--circle[data-on="true"] .gu-mark__loop path {
stroke-dashoffset: 0;
}
/* Windows high contrast: keep a visible cue without the ink. */
@media (forced-colors: active) {
.gu-mark {
outline: 1px solid CanvasText;
}
}
/* Reduced motion: the ink is simply there. */
@media (prefers-reduced-motion: reduce) {
.gu-mark,
.gu-mark__loop path {
transition: none;
}
.gu-mark--marker {
background-size: 100% 72%;
}
.gu-mark--underline {
background-size: 100% 0.14em;
}
.gu-mark__loop path {
stroke-dashoffset: 0;
}
}
```
You might also want
Next piece: Mega menuSplit text reveal
Animations, intermediate, needs motion
Text scramble
Animations, beginner
Odometer counter
Animations, beginner