Hand Drawn
Point at the words that matter, and let the rest stay quiet.
HandDrawnCircleHandDrawnUnderlineHandDrawnDoubleUnderlineHandDrawnScribbleHandDrawnBoxHandDrawnHighlightHandDrawnStrikeHandDrawnBracketsSetup
No dependencies: it is plain React and an inline SVG.
Usage
Wrap any inline text in a shape. Hovering or focusing the text draws the mark in, and moving away rubs it back out.
import { HandDrawnBox, HandDrawnCircle } from "@/components/ui/hand-drawn"
export function Note() {
return (
<p>
We <HandDrawnCircle>shipped</HandDrawnCircle> the new <HandDrawnBox>Deploys</HandDrawnBox> page.
</p>
)
}Shapes
Each shape is its own component, so you only import what you use:
HandDrawnCircle: a loose marker loop around the textHandDrawnUnderline: one slightly curved stroke under the textHandDrawnDoubleUnderline: two strokes, the second a little shorterHandDrawnScribble: a quick zig-zag under the textHandDrawnBox: a rough rectangle around the textHandDrawnHighlight: a translucent highlighter swipe behind the textHandDrawnStrike: a wobbly line through the textHandDrawnBrackets: curved brackets on either side
Drawing from a larger area
By default the text itself is the hover target. To draw the mark when a whole card or row is
hovered, put Tailwind's group class on that element and set trigger="group".
<a href="/docs" className="group block rounded-xl border p-4">
<HandDrawnUnderline trigger="group">Read the docs</HandDrawnUnderline>
<p>Everything you need to get going.</p>
</a>Always on
Set active to show the mark without hovering, for example on the current item in a list.
<HandDrawnCircle active>Today</HandDrawnCircle>Colour
The mark is orange by default and uses currentColor, so any text colour class changes it.
<HandDrawnHighlight markClassName="text-yellow-300">Key idea</HandDrawnHighlight>Your own shape
The shapes are thin wrappers around HandDrawn. Pass it a spec to make your own: an SVG
viewBox, one or more path strings drawn in order, where the mark sits around the text, and a
stroke width.
import { HandDrawn, type HandDrawnProps, type ShapeSpec } from "@/components/ui/hand-drawn"
const ARROW: ShapeSpec = {
viewBox: "0 0 200 40",
paths: ["M2 30C60 26 120 24 190 20", "M176 12L192 20L178 30"],
position: "inset-x-0 top-[80%] h-3",
strokeWidth: 1.75,
}
export function HandDrawnArrow(props: HandDrawnProps) {
return <HandDrawn spec={ARROW} {...props} />
}How it works
- The SVG is stretched to the text's box, while
vector-effect: non-scaling-strokekeeps the line the same width at any size - Each stroke is hidden by a dash as long as the line, and slides into view on hover
- Lines are measured in screen pixels and measured again when the text resizes
- Shapes with more than one stroke draw them one after another
Files
hand-drawn.tsx: the shared engine and theHandDrawncomponentcircle.tsx,underline.tsx,double-underline.tsx,scribble.tsx,box.tsx,highlight.tsx,strike.tsx,brackets.tsx: one shape eachindex.tsx: exports everything
Props
Every shape takes the same props.
| Prop | Type | Default | Notes |
|---|---|---|---|
children | ReactNode | — | The text to mark. Keep it inline and short. |
trigger | "self" | "group" | "self" | Hover the text itself, or the nearest ancestor with the group class. |
active | boolean | false | Show the mark all the time. |
duration | number | 500 | Draw time of each stroke in ms. |
markClassName | string | — | Classes for the mark, e.g. a text colour. |
className | string | — | Applied to the wrapper around the text. |
Accessibility
- The mark is hidden from screen readers; only the text is read
- Keyboard focus on a link or button around the mark draws it, the same as hover
- With reduced motion turned on, the mark appears without the drawing animation