Skip to content
Thrum

Typography

The text styles of the library as components: four headings, lead, paragraph, large, small and muted text, quote, inline code and list. The same styles are exported as class strings. Prose wraps plain HTML, such as rendered markdown, and styles every element inside it.

Install

npx shadcn@latest add https://thrumui.dev/r/typography.json

Adds components/ui/typography.tsx. Nothing else in your project changes.

import { H1 } from "@/components/ui/typography";

Props

PropTypeDefaultDescription
H1ComponentProps<"h1">–32 pixel text on a 36 pixel line, semibold. One per page.
H2ComponentProps<"h2">–24 on 28, semibold. A section.
H3ComponentProps<"h3">–20 on 24, semibold. A subsection.
H4ComponentProps<"h4">–16 on 24, semibold. The smallest heading.
LeadComponentProps<"p">–16 on 24 in the muted colour: the opening paragraph under a title.
PComponentProps<"p">–14 on 20: body text. It sets no margin; space paragraphs with a gap on their container.
LargeComponentProps<"div">–16 on 24, semibold, as a div: a line that stands out without joining the page outline.
SmallComponentProps<"small">–12 on 16, medium weight: a caption or a field hint.
MutedComponentProps<"p">–14 on 20 in the muted colour: secondary text.
BlockquoteComponentProps<"blockquote">–Italic, with a 2 pixel line at the start edge.
InlineCodeComponentProps<"code">–Monospaced at 90% of the surrounding size, on the muted colour.
ListComponentProps<"ul">–A bulleted list with 4 pixels between items. Its children are li elements.
List: orderedbooleanDefault falseA numbered list, rendered as an ol.
ProseComponentProps<"div">–Styles plain h1 to h4, p, a, strong, ul, ol, blockquote, code, pre, table, hr and img elements inside it. At most 65 characters wide, 12 pixels between blocks.
classNamestring–On every component: extra classes, merged last.
typographyRecord<TypographyStyle, string>–A second export: the class string of each style, keyed h1, h2, h3, h4, lead, p, large, small, muted, blockquote, inlineCode and list.

Motion and sound

Motion

  • Text does not move.

Sound

Silent. This component makes no sound.

Accessibility

  • Each component renders the matching HTML element, so headings, lists and quotes reach screen readers as what they are.
  • Pick the heading by the page outline, not by size. Where the two differ, put the class string of the size you want on the right element.
  • Text is the theme's text colour and muted text its muted colour. Both keep 4.5 to 1 on the page, card and popover colours.
  • Links inside Prose are underlined, so they are told from the text around them without colour, and show the 2 pixel focus ring.
  • Headings balance their lines. Headings and Prose break a word that is longer than its line, so nothing is cut off at 160 pixels wide.
  • In Prose, code blocks and tables wrap. Neither scrolls sideways, so no text sits in a box the keyboard cannot reach.
  • No font is loaded: every style uses the font of the page it is in, and the monospaced theme font for code.

Source

components/ui/typography.tsx
"use client";

import type { ComponentProps } from "react";

import { cn } from "@/lib/utils";

/**
 * The text styles as class strings, for an element that is not one of the components below:
 * `<h2 className={typography.h1}>` when the outline says h2 and the design says h1.
 * Sizes and line heights: 32/36, 24/28, 20/24 and 16/24 for headings, 14/20 for text, 12/16 for small print.
 * A heading breaks a word that is longer than its line, so an address or an identifier never overflows.
 */
export const typography = {
  h1: "text-[2rem] leading-9 font-semibold text-balance wrap-break-word text-foreground",
  h2: "text-2xl leading-7 font-semibold text-balance wrap-break-word text-foreground",
  h3: "text-xl leading-6 font-semibold text-balance wrap-break-word text-foreground",
  h4: "text-base leading-6 font-semibold wrap-break-word text-foreground",
  lead: "text-base leading-6 text-muted-foreground",
  p: "text-sm leading-5 text-foreground",
  large: "text-base leading-6 font-semibold text-foreground",
  small: "text-xs leading-4 font-medium text-foreground",
  muted: "text-sm leading-5 text-muted-foreground",
  blockquote: "border-s-2 border-foreground/30 ps-4 text-sm leading-5 text-foreground italic",
  inlineCode: "rounded-sm bg-muted px-1 py-0.5 font-mono text-[0.9em] text-foreground",
  list: "ms-5 list-disc space-y-1 text-sm leading-5 text-foreground marker:text-muted-foreground",
} as const;

export type TypographyStyle = keyof typeof typography;

export function H1({ className, ...props }: ComponentProps<"h1">) {
  return <h1 data-slot="typography-h1" className={cn(typography.h1, className)} {...props} />;
}

export function H2({ className, ...props }: ComponentProps<"h2">) {
  return <h2 data-slot="typography-h2" className={cn(typography.h2, className)} {...props} />;
}

export function H3({ className, ...props }: ComponentProps<"h3">) {
  return <h3 data-slot="typography-h3" className={cn(typography.h3, className)} {...props} />;
}

export function H4({ className, ...props }: ComponentProps<"h4">) {
  return <h4 data-slot="typography-h4" className={cn(typography.h4, className)} {...props} />;
}

/** The opening paragraph under a title: larger and muted. */
export function Lead({ className, ...props }: ComponentProps<"p">) {
  return <p data-slot="typography-lead" className={cn(typography.lead, className)} {...props} />;
}

export function P({ className, ...props }: ComponentProps<"p">) {
  return <p data-slot="typography-p" className={cn(typography.p, className)} {...props} />;
}

/** A line that stands out without being a heading. A `<div>`, so it adds nothing to the page outline. */
export function Large({ className, ...props }: ComponentProps<"div">) {
  return <div data-slot="typography-large" className={cn(typography.large, className)} {...props} />;
}

/** Small print: a caption, a field hint. */
export function Small({ className, ...props }: ComponentProps<"small">) {
  return <small data-slot="typography-small" className={cn(typography.small, className)} {...props} />;
}

export function Muted({ className, ...props }: ComponentProps<"p">) {
  return <p data-slot="typography-muted" className={cn(typography.muted, className)} {...props} />;
}

export function Blockquote({ className, ...props }: ComponentProps<"blockquote">) {
  return <blockquote data-slot="typography-blockquote" className={cn(typography.blockquote, className)} {...props} />;
}

export function InlineCode({ className, ...props }: ComponentProps<"code">) {
  return <code data-slot="typography-inline-code" className={cn(typography.inlineCode, className)} {...props} />;
}

export type ListProps = ComponentProps<"ul"> & {
  /** A numbered list, as an `<ol>`. */
  ordered?: boolean;
};

export function List({ ordered = false, className, ...props }: ListProps) {
  const Tag = ordered ? "ol" : "ul";
  return <Tag data-slot="typography-list" className={cn(typography.list, ordered && "list-decimal", className)} {...(props as ComponentProps<"ol">)} />;
}

// One rule per element kind, so plain HTML from a markdown renderer needs no classes of its own.
const PROSE = [
  "max-w-[65ch] text-sm leading-5 wrap-break-word text-foreground",
  // Vertical rhythm: 12 pixels between blocks, more above a heading.
  "[&>*+*]:mt-3 [&>*:first-child]:mt-0 [&_:is(h1,h2,h3,h4)]:font-semibold [&_:is(h1,h2,h3,h4)]:text-balance [&>:is(h1,h2,h3,h4)+*]:mt-2",
  "[&_h1]:text-[2rem] [&_h1]:leading-9 [&_h2]:text-2xl [&_h2]:leading-7 [&_h3]:text-xl [&_h3]:leading-6 [&_h4]:text-base [&_h4]:leading-6",
  "[&>*+h1]:mt-8 [&>*+h2]:mt-8 [&>*+h3]:mt-6 [&>*+h4]:mt-6",
  "[&_a]:rounded-sm [&_a]:underline [&_a]:underline-offset-4 [&_a:hover]:decoration-2 [&_a:focus-visible]:outline-2 [&_a:focus-visible]:outline-offset-2 [&_a:focus-visible]:outline-ring",
  "[&_strong]:font-semibold",
  "[&_:is(ul,ol)]:ms-5 [&_ul]:list-disc [&_ol]:list-decimal [&_li+li]:mt-1 [&_li::marker]:text-muted-foreground [&_li>:is(ul,ol)]:mt-1",
  "[&_blockquote]:border-s-2 [&_blockquote]:border-foreground/30 [&_blockquote]:ps-4 [&_blockquote]:italic",
  "[&_:not(pre)>code]:rounded-sm [&_:not(pre)>code]:bg-muted [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.9em]",
  // Code blocks and tables wrap instead of scrolling: a scrolling box with nothing to focus in it cannot be reached from the keyboard.
  "[&_pre]:rounded-md [&_pre]:border [&_pre]:bg-muted [&_pre]:p-3 [&_pre]:whitespace-pre-wrap",
  "[&_hr]:my-6 [&_hr]:border-foreground/15",
  "[&_table]:w-full [&_table]:border-collapse [&_table]:text-start [&_table]:tabular-nums",
  "[&_th]:border-b [&_th]:border-foreground/25 [&_th]:px-2 [&_th]:py-1.5 [&_th]:text-start [&_th]:font-medium [&_td]:border-b [&_td]:border-foreground/15 [&_td]:px-2 [&_td]:py-1.5 [&_td]:align-top [&_tbody>tr:last-child>td]:border-b-0",
  "[&_img]:max-w-full [&_img]:rounded-md",
].join(" ");

/**
 * A wrapper that styles plain HTML children: the output of a markdown renderer or a rich text field.
 * Headings, paragraphs, links, lists, quotes, code, tables, rules and images get the same styles as the components above, 65 characters wide at most.
 */
export function Prose({ className, ...props }: ComponentProps<"div">) {
  return <div data-slot="prose" className={cn(PROSE, className)} {...props} />;
}

Files and dependencies

Adds
components/ui/typography.tsx
Packages
None
Brings along
Nothing

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor