Skip to content

shadcn.io is an independent project built on shadcn/ui

Guides

Typography

Style headings, paragraphs, lists, quotes and tables with Tailwind classes on native elements, and Prose for Markdown or CMS HTML you can't add classes to.

On this page11 sections

There's no Typography component to install, in shadcn/ui or here. Text is native elements (h1, p, blockquote, ul, table) with Tailwind classes on them, and this page is the set of classes to start from: copy one onto your element and change it in place. For HTML you didn't write element by element, such as rendered Markdown or a CMS field, Prose styles the elements inside it instead.

Preview width

A short article, The Joke Tax Chronicles, set with these classes only: the title, a muted lead, section headings, paragraphs with a link, a quote, a list and a table. Each part has its own demo and class string below.

Classes or Prose

Your textStyle it with
Written in JSX, element by element: a landing page, a dashboard, an empty stateThe classes on this page, one string per element
HTML you receive whole: Markdown rendered to HTML, a CMS rich-text fieldProse around it, with no class on each element
Markdown from a model, a README or a CMSThe Markdown guide: TanStack Markdown renders it into Prose

Both use the theme's colors, so a page can mix them: a hand-written hero with these classes over a CMS article in Prose.

Headings

h1

Preview width
<h1 className="scroll-m-20 text-balance text-center font-extrabold text-4xl tracking-tight">
  Taxing Laughter: The Joke Tax Chronicles
</h1>

The page title: extrabold at text-4xl, with text-balance so a two-line title breaks evenly instead of leaving one word alone. text-center is this demo's; drop it to line the title up with the text under it, as the article above does. Use one h1 per page.

h2

Preview width
<h2 className="scroll-m-20 border-b pb-2 font-semibold text-3xl tracking-tight first:mt-0">
  The People of the Kingdom
</h2>

A section: semibold at text-3xl, over a rule (border-b pb-2) that marks a new part of the page. first:mt-0 drops the top margin when the heading opens its container. In an article, give it room above: the demo at the top adds mt-10.

h3

Preview width
<h3 className="scroll-m-20 font-semibold text-2xl tracking-tight">
  The Joke Tax
</h3>

A part of a section, at text-2xl with no rule, so it reads as under the h2, not beside it. The article adds mt-8 above it.

h4

Preview width
<h4 className="scroll-m-20 font-semibold text-xl tracking-tight">
  People stopped telling jokes
</h4>

The smallest heading here, at text-xl. Past four levels, the outline is usually too deep: split the page instead.

Body text

Paragraph

Preview width
<p className="leading-7 [&:not(:first-child)]:mt-6">
  The king, seeing how much happier his subjects were, realized the error of
  his ways and repealed the joke tax.
</p>

leading-7 sets a reading line height, and [&:not(:first-child)]:mt-6 spaces each paragraph from what's above it, except the first in its container, so it sits tight under a heading. A link inside takes font-medium text-primary underline underline-offset-4, as in the article at the top.

Lead

Preview width
<p className="text-muted-foreground text-xl">
  A modal dialog that interrupts the user with important content and expects a
  response.
</p>

One larger, muted sentence under the title that says what the page is about. Use it once; the body goes back to the paragraph classes.

Large

Preview width
<div className="font-semibold text-lg">Are you absolutely sure?</div>

A short line with weight, such as a confirmation question. It's a div, not a heading, so it stays out of the page's outline; a section title should still be an h2 to h4.

Small

Preview width
<small className="font-medium text-sm leading-none">Email address</small>

Fine print and compact captions, with leading-none so it sits tight beside a value. It's only a size: when the text names a control, use a Label, which ties the two together.

Muted

Preview width
<p className="text-muted-foreground text-sm">Enter your email address.</p>

Secondary text that shouldn't compete with the main line: a hint, a timestamp, a count. Under a form control, a Field description is the better home, since it stays with the control when the field turns invalid.

Quotes, lists and code

Blockquote

Preview width
<blockquote className="mt-6 border-l-2 pl-6 italic">
  &quot;After all,&quot; he said, &quot;everyone enjoys a good joke, so
  it&apos;s only fair that they should pay for the privilege.&quot;
</blockquote>

A quotation: italic, inset, with a rule on its starting edge. For a warning or a tip, use an Alert instead. For a right-to-left page, write it border-s-2 ps-6, as Right to left shows.

List

Preview width
<ul className="my-6 ml-6 list-disc [&>li]:mt-2">
  <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>
</ul>

[&>li]:mt-2 spaces the items from the list itself, so the li elements need no class. For steps that must stay in order, use an ol with list-decimal and the same spacing.

Inline code

Preview width
<code className="relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono font-semibold text-sm">
  @radix-ui/react-alert-dialog
</code>

A package, a prop or a file name inside a sentence, in mono on a muted chip. Code that runs to several lines belongs in a Code Block.

Tables

Preview width
<div className="my-6 w-full overflow-y-auto">
  <table className="w-full">
    <thead>
      <tr className="m-0 border-t p-0 even:bg-muted">
        <th className="border px-4 py-2 text-left font-bold [&[align=center]]:text-center [&[align=right]]:text-right">
          King&apos;s Treasury
        </th>
      </tr>
    </thead>
    <tbody>
      <tr className="m-0 border-t p-0 even:bg-muted">
        <td className="border px-4 py-2 text-left [&[align=center]]:text-center [&[align=right]]:text-right">
          Empty
        </td>
      </tr>
    </tbody>
  </table>
</div>

A small table inside an article: bordered cells, a bold header row, and every other body row on bg-muted. The wrapper scrolls when the columns are wider than the text, and the [&[align=…]] variants honor a cell's align attribute. For data people sort, filter or select, use Table and the data table guide instead.

Spacing and anchors

Three modifiers recur in these classes:

ClassWhat it does
[&:not(:first-child)]:mt-6Adds space above the element unless it's the first in its container, so text never starts with a gap
first:mt-0Removes a heading's top margin when it opens its container
scroll-m-20Leaves 5rem above a heading when a link scrolls to it, so a sticky header doesn't cover it

To link to a heading, give it an id (<h2 id="the-plan">) and link to #the-plan. The spacing lives on the top of each element (mt-*), so the gap above a heading is the heading's own margin, whatever comes before it.

Colors and fonts

The colors are theme tokens: text-muted-foreground for the lead and muted text, bg-muted for code and table rows, text-primary for links. border, border-b and border-l-2 draw in the theme's border color, which the preset gives every element. Your preset defines each token for light and dark, so the text follows the theme with no dark: classes.

Apart from font-mono on inline code, none of these classes picks a typeface: the text uses the page's font, which the preset sets on body with font-sans. The preset's font-sans, font-heading and font-mono read the --font-sans, --font-heading and --font-mono CSS variables and fall back to the system fonts while those are unset. Add font-heading to the headings to give them their own face.

Right to left

Preview width

The same article in Arabic, with dir="rtl" on its wrapper. The quote's rule, the list's indent and the table's alignment start on the right, because the classes are logical:

Left to right onlyBoth directions
ml-6 on the listms-6
border-l-2 pl-6 on the blockquoteborder-s-2 ps-6
text-left on table cellstext-start

Logical classes render the same as the physical ones in a left-to-right page, so you can write them everywhere. Set dir on the page or the element that holds the text; for menus and popups to follow it too, wrap the region in Direction's provider.

Reuse the classes

When a class string repeats across your app, give it a small component of your own. cn merges the class you pass last, so <H2 className="text-2xl"> replaces text-3xl rather than adding to it:

components/typography.tsx
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";

export const H2 = ({ className, ...props }: ComponentProps<"h2">) => (
  <h2
    className={cn(
      "scroll-m-20 border-b pb-2 font-semibold text-3xl tracking-tight first:mt-0",
      className
    )}
    {...props}
  />
);

Prose for HTML you didn't write

A CMS field or a Markdown file arrives as finished HTML, with no place for a class on each element. Wrap it in Prose instead:

shadcn CLILocked
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
import { Prose } from "@/components/ui/prose";

export const Post = (props: { html: string }) => (
  <Prose asChild>
    <article dangerouslySetInnerHTML={{ __html: props.html }} />
  </Prose>
);

The install adds Prose's element styles to your global CSS: headings, paragraphs, links, lists, quotes, tables, inline code, keyboard keys, marks, figures, images and details, in the same theme tokens as the classes above. Edit them there to change the look of every article at once. Prose caps its width at a readable 37em and centers itself; pass className="max-w-none" to fill the container. asChild puts its styles on your own element, here an article.

dangerouslySetInnerHTML renders whatever the string holds, so sanitize HTML that comes from outside your codebase first. For Markdown, the Markdown guide renders the string into React elements inside Prose, with no HTML string at all.

FAQ

Is there a Typography component in shadcn?

No. shadcn/ui documents typography as Tailwind classes on native elements, and so does this page: copy the class string onto your h1, p or ul. For HTML you can't add classes to, such as rendered Markdown, wrap it in Prose.

Should I use Prose or the typography classes?

The classes when you write the text in JSX, element by element, and want to choose each heading's look. Prose when the HTML comes whole from somewhere else, a CMS or a Markdown renderer, so its elements are styled by where they sit. A page can use both.

How do I make headings larger on big screens?

Add a breakpoint to the class string, such as text-4xl lg:text-5xl on the h1. There's no size prop: the classes are the API, and you change them in place.

Why does a sticky header cover my heading when I link to it?

The browser scrolls the heading to the very top, under the header. scroll-m-20 on the heading leaves 5rem above it when it's scrolled into view; raise it if your header is taller than that.

What does [&:not(:first-child)]:mt-6 do?

It adds margin-top: 1.5rem to the element unless it's the first child of its parent. Paragraphs get space between them, and the first one doesn't push its container's content down.

Does the typography work in dark mode?

Yes, with nothing to add. The colors are theme tokens, text-muted-foreground, bg-muted, text-primary and the border color, and your preset defines each for light and dark.

Which font does the typography use?

The page's font, which the preset sets on body with font-sans; only inline code sets font-mono. The preset's font utilities read --font-sans, --font-heading and --font-mono and fall back to the system fonts, so set those variables to change the typeface.

How do I support right-to-left languages?

Use logical classes, ms-6 instead of ml-6, border-s-2 ps-6 instead of border-l-2 pl-6, text-start instead of text-left, and set dir="rtl" on the element that holds the text. The RTL demo shows the article set that way.

What's the difference between Large and an h4?

An h4 is a heading: it's in the page's outline and screen readers list it. Large is a div with font-semibold text-lg, for emphasis that isn't a section title, such as a confirmation question.

Can I use these classes in Vue, Svelte or Solid?

Yes. They're plain Tailwind classes: write them in class instead of className. Prose has Vue, Svelte and Solid versions too, each installed from its page.