Hand Drawn

Point at the words that matter, and let the rest stay quiet.

ShippedHandDrawnCircle
ImportantHandDrawnUnderline
Must readHandDrawnDoubleUnderline
DraftHandDrawnScribble
v2.0HandDrawnBox
Key ideaHandDrawnHighlight
$49HandDrawnStrike
optionalHandDrawnBrackets

Setup

$npx shadcn@latest add https://kinetikui.singhgourav.site/r/hand-drawn.json

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.

Example
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 text
  • HandDrawnUnderline: one slightly curved stroke under the text
  • HandDrawnDoubleUnderline: two strokes, the second a little shorter
  • HandDrawnScribble: a quick zig-zag under the text
  • HandDrawnBox: a rough rectangle around the text
  • HandDrawnHighlight: a translucent highlighter swipe behind the text
  • HandDrawnStrike: a wobbly line through the text
  • HandDrawnBrackets: 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".

Example
<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.

Example
<HandDrawnCircle active>Today</HandDrawnCircle>

Colour

The mark is orange by default and uses currentColor, so any text colour class changes it.

Example
<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.

Example
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-stroke keeps 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 the HandDrawn component
  • circle.tsx, underline.tsx, double-underline.tsx, scribble.tsx, box.tsx, highlight.tsx, strike.tsx, brackets.tsx: one shape each
  • index.tsx: exports everything

Props

Every shape takes the same props.

PropTypeDefaultNotes
childrenReactNode—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.
activebooleanfalseShow the mark all the time.
durationnumber500Draw time of each stroke in ms.
markClassNamestring—Classes for the mark, e.g. a text colour.
classNamestring—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