opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Underlines
  4. Annotated Text
Back to Underlines

Components / Underlines

Annotated Text

Free Underlines React component — AnnotatedText. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Hand-drawn text annotations — wavy underlines, highlights, arrows, brackets, and more. Pass variant and optional color to style any inline label or callout.

Preview

Wavy underlineCircled textHighlighted textSimple underlineStraight lineDotted underlineDouble underlineCrossed outArrow underline

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/underlines/annotated-text.tsx in your project.

  4. 4

    Import and render:

    Example

    import { AnnotatedText } from "@/components/underlines/annotated-text";

    <AnnotatedText variant="wavy" color="text-purple-300">Wavy underline</AnnotatedText>
    <AnnotatedText variant="circle" color="text-cyan-200">Circled text</AnnotatedText>
    <AnnotatedText variant="highlight" color="text-yellow-100">Highlighted text</AnnotatedText>
    <AnnotatedText variant="underline" color="text-cyan-200">Simple underline</AnnotatedText>
    <AnnotatedText variant="line" color="text-orange-300">Straight line</AnnotatedText>
    <AnnotatedText variant="dottedUnderline">Dotted underline</AnnotatedText>
    <AnnotatedText variant="doubleUnderline">Double underline</AnnotatedText>
    <AnnotatedText variant="crossOut" color="text-red-400">Crossed out</AnnotatedText>
    <AnnotatedText variant="arrow" color="text-rose-300">Arrow underline</AnnotatedText>

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/underlines/annotated-text.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
import { forwardRef, type ReactNode } from "react";
 
import { cn } from "@/lib/cn";
 
function RoughFilters() {
return (
<svg className="absolute h-0 w-0" aria-hidden="true">
<defs>
<filter id="hd-rough" x="-30%" y="-30%" width="160%" height="160%">
<feTurbulence
type="fractalNoise"
baseFrequency={0.045}
numOctaves={2}
seed={4}
result="n"
/>
<feDisplacementMap
in="SourceGraphic"
in2="n"
scale={2.6}
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
<filter id="hd-rough-soft" x="-30%" y="-30%" width="160%" height="160%">
<feTurbulence
type="fractalNoise"
baseFrequency={0.035}
numOctaves={2}
seed={11}
result="n2"
/>
<feDisplacementMap
in="SourceGraphic"
in2="n2"
scale={1.5}
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
</defs>
</svg>
);
}
 
function WavyDecoration({ className }: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 140 14"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M2,6 Q5.5,3 9,6 T17,6 T25,6 T33,6 T41,6 T49,6 T57,6 T65,6 T73,6 T81,6 T89,6 T97,6 T105,6 T113,6 T121,6 T129,6 T137,6"
stroke="currentColor"
strokeWidth={2.2}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function CircleDecoration({ className }: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 220 64"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M40,40 C20,23 53,7 102,5 C153,3 207,11 211,29 C215,47 167,60 109,60
C59,60 15,53 19,35 C21,27 27,22 37,20"
stroke="currentColor"
strokeWidth={3}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough)"
/>
<path
d="M43,37 C28,25 58,9 105,7 C151,6 199,14 206,29 C212,45 167,57 110,58"
stroke="currentColor"
strokeWidth={1.5}
strokeLinecap="round"
fill="none"
opacity={0.55}
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function HighlightDecoration({ className }: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 170 26"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M4,17 C2,11 5,7 12,6 C45,2 95,2 138,4 C152,5 164,7 166,13
C167,18 163,21 155,22 C112,24 60,24 16,22 C8,21.5 4,20 4,17 Z"
fill="currentColor"
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function UnderlineDecoration({ className }: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 140 10"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M3,6 C40,3 100,3 137,5"
stroke="currentColor"
strokeWidth={2.4}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function LineDecoration({ className }: Readonly<{ className?: string }>) {
return (
<span
aria-hidden="true"
className={cn("block rounded-full bg-current", className)}
/>
);
}
 
function DottedUnderlineDecoration({
className,
}: Readonly<{ className?: string }>) {
return (
<span
aria-hidden="true"
className={cn(
"bg-[radial-gradient(circle,currentColor_1.5px,transparent_1.5px)]",
"bg-size-[0.5em_100%] bg-position-[0_100%] bg-repeat-x",
className,
)}
/>
);
}
 
function DoubleUnderlineDecoration({
className,
}: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 140 16"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M3,5 C40,2 100,2 137,4"
stroke="currentColor"
strokeWidth={2.2}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough-soft)"
/>
<path
d="M5,12 C42,9 98,10 135,11"
stroke="currentColor"
strokeWidth={1.8}
strokeLinecap="round"
fill="none"
opacity={0.75}
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function StrikethroughDecoration({
className,
}: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 140 10"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M3,5 C40,7 100,3 137,5"
stroke="currentColor"
strokeWidth={2.4}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function CrossOutDecoration({ className }: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 140 40"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M4,32 C40,10 96,30 136,8"
stroke="currentColor"
strokeWidth={2.4}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough)"
/>
<path
d="M6,10 C44,30 92,12 134,30"
stroke="currentColor"
strokeWidth={2}
strokeLinecap="round"
fill="none"
opacity={0.7}
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function ArrowUnderlineDecoration({
className,
}: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 150 18"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M3,7 C45,3 105,4 140,8"
stroke="currentColor"
strokeWidth={2.4}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough-soft)"
/>
<path
d="M132,3 L142,8 L131,13"
stroke="currentColor"
strokeWidth={2.4}
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
filter="url(#hd-rough-soft)"
/>
</svg>
);
}
 
function BracketDecoration({ className }: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 160 60"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M18,6 C9,7 6,12 6,30 C6,48 9,53 18,54"
stroke="currentColor"
strokeWidth={2.6}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough)"
/>
<path
d="M142,6 C151,7 154,12 154,30 C154,48 151,53 142,54"
stroke="currentColor"
strokeWidth={2.6}
strokeLinecap="round"
fill="none"
filter="url(#hd-rough)"
/>
</svg>
);
}
 
function BoxDecoration({ className }: Readonly<{ className?: string }>) {
return (
<svg
className={className}
viewBox="0 0 200 64"
fill="none"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M12,10 C60,6 140,6 188,10 C193,26 193,40 188,54
C140,58 60,58 12,54 C7,40 7,26 12,10 Z"
stroke="currentColor"
strokeWidth={2.6}
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
filter="url(#hd-rough)"
/>
</svg>
);
}
 
const annotationStyles = {
wavy: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: WavyDecoration,
decorationClassName:
"pointer-events-none absolute bottom-[-0.4em] left-[-2%] h-[0.7em] w-[104%]",
defaultColor: "text-purple-300",
},
circle: {
wrapper: "relative inline-block px-1 whitespace-nowrap",
Decoration: CircleDecoration,
decorationClassName:
"pointer-events-none absolute inset-[-0.6em_-0.55em] h-[calc(100%+1.2em)] w-[calc(100%+1.1em)]",
defaultColor: "text-cyan-200",
},
highlight: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: HighlightDecoration,
decorationClassName:
"pointer-events-none absolute inset-x-[-4%] bottom-[-0.08em] z-0 h-[1.15em] w-[108%]",
defaultColor: "text-yellow-300/60",
},
underline: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: UnderlineDecoration,
decorationClassName:
"pointer-events-none absolute bottom-[-0.32em] left-[-1%] h-[0.5em] w-[102%]",
defaultColor: "text-purple-400",
},
line: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: LineDecoration,
decorationClassName:
"pointer-events-none absolute bottom-[-0.18em] left-[-1%] block h-[2px] w-[102%]",
defaultColor: "text-neutral-500",
},
dottedUnderline: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: DottedUnderlineDecoration,
decorationClassName:
"pointer-events-none absolute bottom-[-0.35em] left-[-1%] block h-[0.55em] w-[102%]",
defaultColor: "text-neutral-400",
},
doubleUnderline: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: DoubleUnderlineDecoration,
decorationClassName:
"pointer-events-none absolute bottom-[-0.5em] left-[-1%] h-[0.7em] w-[102%]",
defaultColor: "text-emerald-400",
},
strikethrough: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: StrikethroughDecoration,
decorationClassName:
"pointer-events-none absolute top-1/2 left-[-1%] h-[0.5em] w-[102%] -translate-y-1/2",
defaultColor: "text-red-400",
},
crossOut: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: CrossOutDecoration,
decorationClassName:
"pointer-events-none absolute top-1/2 left-[-2%] h-[1.4em] w-[104%] -translate-y-1/2",
defaultColor: "text-red-400",
},
arrow: {
wrapper: "relative inline-block whitespace-nowrap",
Decoration: ArrowUnderlineDecoration,
decorationClassName:
"pointer-events-none absolute bottom-[-0.45em] left-[-1%] h-[0.8em] w-[106%]",
defaultColor: "text-blue-400",
},
bracket: {
wrapper: "relative inline-block px-[0.35em] whitespace-nowrap",
Decoration: BracketDecoration,
decorationClassName:
"pointer-events-none absolute inset-y-[-0.25em] left-[-0.15em] h-[calc(100%+0.5em)] w-[calc(100%+0.3em)]",
defaultColor: "text-neutral-500",
},
box: {
wrapper: "relative inline-block px-[0.4em] whitespace-nowrap",
Decoration: BoxDecoration,
decorationClassName:
"pointer-events-none absolute inset-[-0.4em_-0.4em] h-[calc(100%+0.8em)] w-[calc(100%+0.8em)]",
defaultColor: "text-orange-400",
},
} as const;
 
type AnnotationVariant = keyof typeof annotationStyles;
 
type AnnotatedTextProps = Readonly<{
children: ReactNode;
variant?: AnnotationVariant;
color?: string;
className?: string;
}>;
 
export const AnnotatedText = forwardRef<HTMLSpanElement, AnnotatedTextProps>(
({ children, variant = "wavy", color, className }, ref) => {
const style = annotationStyles[variant];
const Decoration = style.Decoration;
const decorationClass = cn(
style.decorationClassName,
color ?? style.defaultColor,
);
 
// Variants whose decoration sits behind the text (avoids covering glyphs).
const isBehindText = variant === "highlight";
 
if (isBehindText) {
return (
<>
<RoughFilters />
<span ref={ref} className={cn(style.wrapper, className)}>
<span className="relative z-10 font-normal text-neutral-950">
{children}
</span>
<Decoration className={cn(decorationClass, "z-0")} />
</span>
</>
);
}
 
return (
<>
<RoughFilters />
<span
ref={ref}
className={cn(
style.wrapper,
"font-normal text-neutral-950",
className,
)}
>
{children}
<Decoration className={decorationClass} />
</span>
</>
);
},
);
 
AnnotatedText.displayName = "AnnotatedText";
Previous

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/underlines/annotated-text.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.