Skip to content

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

Components

Free

Prose for UI SDK

A React typography wrapper for UI SDK that styles rendered Markdown and CMS HTML by element, plus Tailwind classes for each heading, list and table.

On this page9 sections

Prose is for markup you can't put classes on: Markdown rendered to HTML, a body field from a CMS, a changelog. Wrap it once, and a stylesheet styles the headings, paragraphs, lists, tables and quotes inside by their element, as in the preview below. The demos after it are the other half, the Tailwind classes for each element on a page you build by hand.

Put code that runs past one line in a Code Block, which adds a title, a copy button and line numbers.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Prose anatomy: root, h1, p, blockquote, ul, code

Usage

import { Prose } from "@/components/ui/prose";

Everything inside is plain markup with no classes. The install adds the rules that style it to your global stylesheet, and they apply under the typeset class Prose sets on its div.

<Prose>
  <h2>Release notes</h2>
  <p>
    Version 2.4 adds CSV export to every table and fixes the date filter.
  </p>
  <ul>
    <li>Export any table as CSV</li>
    <li>Filter dates in your own time zone</li>
  </ul>
</Prose>

Accessibility

Prose adds no role and takes no focus. It renders a div, so screen readers meet the elements inside as they are, and the styles key on those same elements. A heading has to be a real h1 to h6 element to look like one and to show up in the page's outline. Markdown's # becomes an h1, which gives a page that already has a title a second one, so start the content at ## or shift the levels in your Markdown renderer. For an article element in place of the div, pass render={<article />}, and the classes land on it.

Demos

H1

The article title, "Taxing Laughter: The Joke Tax Chronicles", at text-4xl and extrabold with tight tracking. text-balance evens out its wrapped lines, and scroll-m-20 keeps it clear of a sticky header when a link jumps to it. The centering belongs to this demo only, so drop text-center when the title should line up with the body.

Preview width

H2

A section heading at text-3xl and semibold, with a bottom border and pb-2 that rule off the next part of the article. Give it a top margin, as the RTL article does with mt-10, and first:mt-0 drops that margin when the heading opens its column. Use it between the major parts of a page.

Preview width

H3

A subsection heading, "The Joke Tax", at text-2xl and semibold with no rule under it, so it doesn't read as another H2. Reach for it when a section has parts of its own, as the tax rates do under the king's plan in the RTL article. It carries the same scroll-m-20 offset as the title, for links that jump to it.

Preview width

H4

The smallest heading here, "People stopped telling jokes", at text-xl and semibold. Use it inside an H3 section when a part still needs a title in the page's outline. When the words are emphasis rather than the start of a section, the Large style gives them weight and stays out of the outline.

Preview width

P

One paragraph of the story at leading-7, with an mt-6 top margin that applies only when it isn't the first child. That keeps a paragraph tight under its heading and spaced from the one before it. Use it for body copy, and the Lead style for the larger, muted sentence under a title.

Preview width

Blockquote

The king's line about paying for jokes, set in italic with a 2px left border and pl-6 of inset. Use it for a quotation inside the article, and an Alert for a warning or a tip. The border sits on the physical left, so the RTL demo switches to border-s-2 and ps-6.

Preview width

Table

The king's treasury against the people's mood: three rows under a bold header row, every cell bordered and the even rows muted. The wrapper has overflow-y-auto, so a table wider than its column scrolls sideways inside it instead of widening the page. Use it for a handful of facts in an article, and a Table for data people sort and scan.

Preview width

List

The three joke tax rates as a disc list, indented with ml-6 and spaced with mt-2 between items. The numbers are part of each item's text, so the list stays unordered. Use it for rules and rates that should scan, and an ordered list with the same spacing for steps that have to stay in sequence.

Preview width

Inline code

A package name, @radix-ui/react-alert-dialog, on a muted chip in a monospace font at text-sm and semibold, with a little padding. Use it for a name inside a sentence, such as a package or a prop, and a Code Block for anything that runs past one line.

Preview width

Lead

The sentence under a title that says what the page is about, at text-xl in the muted color. Use one per page, before the body starts, and set everything after it in the P style. Two lead lines in a row read as a stack of large text with no introduction.

Preview width

Large

The question "Are you absolutely sure?" at text-lg and semibold. It is a div, not a heading, so it stays out of the page's outline. Use it for a line that needs weight without naming a section, such as a confirmation question, and a real heading when the text does name one.

Preview width

Small

The label "Email address" in a small element at text-sm and medium weight, with leading-none collapsing its line height. It suits fine print and a compact label beside a value. When the text names a form control, use a Label, so a click on the text reaches that control.

Preview width

Muted

The hint "Enter your email address." at text-sm in the muted foreground color, the line that sits under a field. Use it for secondary copy that shouldn't compete with the label. Inside a form, the Field component has a description part for this same line.

Preview width

RTL

The whole joke tax article in Arabic, with dir set to rtl on its wrapper. The list indents with ms-6, the quote takes border-s-2 and ps-6, and the table cells align with text-start, so each follows the reading direction. The other demos use physical left classes, which stay on the left in a right-to-left page.

Preview width

FAQ

How do I render Markdown or CMS HTML with Prose in React?

Turn the Markdown into HTML with your parser, and put that HTML inside Prose. In React, pass it to dangerouslySetInnerHTML on Prose itself or on an element inside it. The headings, lists and tables in it take the article styles with no class of their own.

Sanitize HTML that users can write before you render it, because it goes into the page exactly as it is.

For Markdown, the Markdown guide skips the HTML string: TanStack Markdown renders React elements straight into Prose.

How do I make Prose fill its container instead of a narrow column?

Prose caps its width with max-w-[37em] and centers itself with mx-auto, which holds lines to a readable length in a wide layout. Add max-w-none to its className to let it fill its container, or another max-w-* value for a different measure.

The classes merge through cn, so yours replaces the cap instead of fighting it. Add mx-0 as well when the column should sit at the start edge rather than in the middle.

Should I use Prose or put Tailwind classes on each heading?

Use Prose for markup you don't write element by element: Markdown, a CMS field, help articles kept as files. For a page you build by hand, put the classes on each element instead, as the demos on this page do from H1 to Muted.

The two mix well. A landing page built by hand can still hold one Prose block for its terms of service, and each part keeps the styles it was written for.

Does Prose need prose-invert for dark mode?

No, there is no prose-invert class to add. The rules the install adds read your theme's variables instead of fixed colors: text and headings use --color-foreground, list markers, captions and table heads the muted foreground, inline code and pre blocks --color-muted, and the rules of quotes, tables and dividers --color-border. Links inherit the text color and draw their underline from it.

Those switch with the rest of your theme under .dark. The one fixed color is the yellow behind mark, a 40% tint that is the same in both modes.

Does Prose work with right-to-left languages?

Set dir to rtl on Prose or a parent, and both the text and the styles follow it, because the rules the install adds use logical sides. Lists indent with padding-inline-start, quotes draw a border-inline-start, and table cells align to start, so in Arabic or Hebrew all three sit on the right with no change.

A pre block stays left to right, since code reads that way in any language. The RTL demo builds the same article by hand with Tailwind's logical classes, such as ms-6 and border-s-2.

How do I change the Prose heading sizes or link color?

Change the variables on the .typeset-docs rule the install added to your global stylesheet. --typeset-size is the body size every heading is measured from, --typeset-leading the line height, --typeset-flow the space between blocks and --typeset-font-heading the heading font. Prose sets both typeset and typeset-docs, and .typeset-docs comes after .typeset, so its values win.

For one element, edit its rule in the same @layer components block, where an h2 is 1.25em and a link inherits the text color under an underline. The component file in components/ui holds only the wrapper and its width, so there is nothing to change there for the type itself.

How do I keep Prose from styling a component inside it?

Add a not-typeset class to that component's root element, or a data-not-typeset attribute. The rules the install adds skip that element and everything inside it, so a card, a form or a chart placed in the article keeps its own look.

A Code Block needs neither. The rules already leave its content alone, and a block placed directly in Prose gets the same space above it as a paragraph.

API Reference

Prose

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Renders your own element, like an <article>, with the prose styles.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.