Typography
Headings, paragraphs, quotes, lists and small print in the hand, with the pen rules drawn under and beside them.
The Joke Tax Chronicles
Once upon a time, in a far-off land, there was a very lazy king who spent all day lounging on his throne. One day, his advisors came to him with a problem: the kingdom was running out of money.
The King's Plan
The king thought long and hard, and finally came up with a brilliant plan: he would tax the jokes in the kingdom.
"After all," he said, "everyone enjoys a good joke, so it's only fair that they should pay for the privilege."
The Joke Tax
The king's subjects were not amused. They grumbled and complained, but the king was firm:
- 1st level of puns: 5 gold coins
- 2nd level of jokes: 10 gold coins
- 3rd level of one-liners: 20 gold coins
import {
TypographyBlockquote,
TypographyH1,
TypographyH2,
TypographyH3,
TypographyInlineCode,
TypographyList,
TypographyP,
} from "@/components/ui/typography";
export default function TypographyDemo() {
return (
<article className="flex w-full max-w-2xl flex-col gap-1">
<TypographyH1>The Joke Tax Chronicles</TypographyH1>
<TypographyP>
Once upon a time, in a far-off land, there was a very lazy king who spent all day lounging on his throne. One day, his advisors came to him with a
problem: the kingdom was running out of money.
</TypographyP>
<TypographyH2 className="mt-8">The King's Plan</TypographyH2>
<TypographyP>
The king thought long and hard, and finally came up with <TypographyInlineCode>a brilliant plan</TypographyInlineCode>: he would tax the jokes in the
kingdom.
</TypographyP>
<TypographyBlockquote>"After all," he said, "everyone enjoys a good joke, so it's only fair that they should pay for the privilege."</TypographyBlockquote>
<TypographyH3 className="mt-8">The Joke Tax</TypographyH3>
<TypographyP>The king's subjects were not amused. They grumbled and complained, but the king was firm:</TypographyP>
<TypographyList>
<li>1st level of puns: 5 gold coins</li>
<li>2nd level of jokes: 10 gold coins</li>
<li>3rd level of one-liners: 20 gold coins</li>
</TypographyList>
</article>
);
}Installation
pnpm dlx shadcn@latest add @ballpoint/ typographyimport type { ComponentProps } from "react";
import { cn } from "@/lib/utils";
import { Separator } from "@/components/ui/separator";
// shadcn documents typography as classes to copy; here they are components,
// so the pen rules under a heading and beside a quote are drawn too.
function TypographyH1({ className, ...props }: ComponentProps<"h1">) {
return <h1 data-slot="typography-h1" className={cn("scroll-m-20 text-4xl leading-tight font-bold text-balance md:text-5xl", className)} {...props} />;
}
/** A second-level heading, ruled off with a pen line. */
function TypographyH2({ className, children, ...props }: ComponentProps<"h2">) {
return (
<h2 data-slot="typography-h2" className={cn("scroll-m-20 text-3xl leading-tight font-bold first:mt-0", className)} {...props}>
{children}
<Separator className="mt-1.5" />
</h2>
);
}
function TypographyH3({ className, ...props }: ComponentProps<"h3">) {
return <h3 data-slot="typography-h3" className={cn("scroll-m-20 text-2xl leading-snug font-bold", className)} {...props} />;
}
function TypographyH4({ className, ...props }: ComponentProps<"h4">) {
return <h4 data-slot="typography-h4" className={cn("scroll-m-20 text-xl leading-snug font-bold", className)} {...props} />;
}
function TypographyP({ className, ...props }: ComponentProps<"p">) {
return <p data-slot="typography-p" className={cn("text-base leading-7 text-ink-2 [&:not(:first-child)]:mt-5", className)} {...props} />;
}
/** A quotation set off with a pen line down its side. */
function TypographyBlockquote({ className, children, ...props }: ComponentProps<"blockquote">) {
return (
<blockquote data-slot="typography-blockquote" className={cn("relative mt-6 pl-6 text-lg text-ink-2 italic", className)} {...props}>
<Separator orientation="vertical" className="absolute inset-y-0 left-0 text-ink-line" />
{children}
</blockquote>
);
}
function TypographyList({ className, ...props }: ComponentProps<"ul">) {
return <ul data-slot="typography-list" className={cn("my-5 ml-6 list-disc text-base text-ink-2 marker:text-ink-3 [&>li]:mt-1.5", className)} {...props} />;
}
function TypographyInlineCode({ className, ...props }: ComponentProps<"code">) {
return <code data-slot="typography-inline-code" className={cn("relative bg-ink-5 px-[0.35rem] py-[0.1rem] font-mono text-sm text-ink", className)} {...props} />;
}
function TypographyLead({ className, ...props }: ComponentProps<"p">) {
return <p data-slot="typography-lead" className={cn("text-xl text-ink-3", className)} {...props} />;
}
function TypographyLarge({ className, ...props }: ComponentProps<"div">) {
return <div data-slot="typography-large" className={cn("text-lg font-bold", className)} {...props} />;
}
function TypographySmall({ className, ...props }: ComponentProps<"small">) {
return <small data-slot="typography-small" className={cn("text-sm leading-none font-bold", className)} {...props} />;
}
function TypographyMuted({ className, ...props }: ComponentProps<"p">) {
return <p data-slot="typography-muted" className={cn("text-sm text-ink-3", className)} {...props} />;
}
export {
TypographyBlockquote,
TypographyH1,
TypographyH2,
TypographyH3,
TypographyH4,
TypographyInlineCode,
TypographyLarge,
TypographyLead,
TypographyList,
TypographyMuted,
TypographyP,
TypographySmall,
};Usage
import { TypographyH1, TypographyH2, TypographyP } from "@/components/ui/typography"
<TypographyH1>Field notes</TypographyH1>
<TypographyP>The first page of a new notebook.</TypographyP>
<TypographyH2>Materials</TypographyH2>Examples
Lead, large, small and muted
The quieter text styles for the margins of a page.
A modal dialog that interrupts the user with important content and expects a response.
Enter your email address.
import { TypographyLarge, TypographyLead, TypographyMuted, TypographySmall } from "@/components/ui/typography";
export default function TypographySmallText() {
return (
<div className="flex w-full max-w-lg flex-col gap-5">
<TypographyLead>A modal dialog that interrupts the user with important content and expects a response.</TypographyLead>
<TypographyLarge>Are you absolutely sure?</TypographyLarge>
<TypographySmall>Email address</TypographySmall>
<TypographyMuted>Enter your email address.</TypographyMuted>
</div>
);
}API reference
- TypographyH1 … H4
h1 … h4Headings. H2 is ruled off with a pen line.
- TypographyP
pBody text, with space above every paragraph but the first.
- TypographyBlockquote
blockquoteA quotation with a pen line drawn down its side.
- TypographyList / InlineCode
ul / codeA bulleted list, and a snippet of code in a line of text.
- TypographyLead / Large / Small / Muted
p / div / small / pIntroductory text, emphasis, fine print and quiet hints.