typeset
One stylesheet that styles rendered markdown and HTML, from docs pages to streaming chat.
When to use it
Rendered markdown comes back as bare HTML. Without styles you end up sizing headings, spacing lists, and padding tables by hand, once for the blog, again for the docs, and again for the chat panel.
Typeset styles everything inside one wrapper, so you never add classes to a <p> or <li>. Reach for it when you don't control the markup: markdown, CMS content, or AI answers.
Use typography when you write the JSX yourself and want a component per element.
Installation
npx @gentleduck/cli add typeset
npx @gentleduck/cli add typeset
The CLI copies typeset.css with the component and imports it in the CSS file set in duck-ui.config.json, right after Tailwind.
Usage
import { Typeset } from "@/components/ui/typeset"
Wrap the rendered content. Any markdown renderer works.
import Markdown from "react-markdown"
<Typeset>
<Markdown>{content}</Markdown>
</Typeset>
The component only adds the typeset class, so plain HTML works too.
<article class="typeset">...</article>
Rhythm
Type has a lot of dials: scale ratios, tracking, measure, the space above and below every element. Exposing all of them makes markdown harder to style, not easier.
Typeset keeps three. Heading sizes, list indents, the gap under a heading, and the space around a rule all derive from them.
| Variable | Default | Controls |
|---|---|---|
--typeset-size | 1em | Base font size. 1em follows the surrounding text |
--typeset-leading | 1.75 | Line height |
--typeset-flow | 1.25em | Space between blocks |
Three more pick the font families. Leave them alone and Typeset follows your app.
| Variable | Default |
|---|---|
--typeset-font-body | inherit |
--typeset-font-heading | var(--font-heading, inherit) |
--typeset-font-mono | var(--font-mono) |
Colors, borders, and radius come from your theme tokens, so dark mode needs no extra setup. Typeset never sets a max-width; your layout owns the measure.
Because sizes are relative, the same stylesheet fits a chat bubble and a full article. On screens narrower than 40rem the base size gets a small bump for readability.
Sizes
size sets the three rhythm variables for you. Use sm for chat and side panels, lg for long reads.
Presets
A preset is a class that sets the variables. Keep as many as you need, one per context.
.typeset-chat {
--typeset-flow: 1em;
--typeset-leading: 1.6;
}
.typeset-docs {
--typeset-size: 15px;
--typeset-flow: 1.5em;
}
<Typeset className="typeset-chat">{message}</Typeset>
<Typeset asChild className="typeset-docs">
<article>{page}</article>
</Typeset>
For a one-off change, set a value on the wrapper instead.
Presets can change the whole feel, not just the spacing. A serif reading mode and a compact UI mode are two classes:
.typeset-reading {
--typeset-font-body: var(--font-serif);
--typeset-font-heading: var(--font-serif);
--typeset-size: 18px;
--typeset-leading: 1.9;
--typeset-flow: 2em;
}
.typeset-compact {
--typeset-size: 14px;
--typeset-leading: 1.6;
--typeset-flow: 1em;
}
Accessibility and dark mode
Offer a roomier preset as a reading setting for people who want larger type and more space.
.typeset-large {
--typeset-size: 1.125rem;
--typeset-leading: 2;
--typeset-flow: 2em;
}
Light text on a dark surface can feel tighter. Loosen the leading only there:
.dark .typeset {
--typeset-leading: 1.85;
}
Streaming
Typeset is built so a new block never restyles the blocks already on screen.
- Blocks only get
margin-block-start, so each new block brings its own space. - Layout rules avoid
:last-child,:has(), and:empty, whose matches change as content arrives. - Table rows carry their own borders, so a new row leaves the one above it alone.
Opting out
Add data-not-typeset or the not-typeset class to a component inside the prose. It keeps its own styles, and so do its children.
A Typeset nested inside an opted-out component turns styling back on for its own content, so a preview card can still show prose.
Wide tables
Tables wrap by default. Wrap a wide table in typeset-scroll to scroll it instead. The easiest place is your renderer's table component.
<div className="typeset-scroll">
<table>...</table>
</div>
Overrides
Typeset lives in @layer components and uses :where(), so any Tailwind utility on an element wins without !important. A plain CSS selector wins too.
<Typeset>
<h2 className="text-primary">Overrides the heading color</h2>
</Typeset>
Compared with typography plugins
@tailwindcss/typography and its prose class are a great fit for static pages. Typeset trades a few of its choices for app content:
prose | Typeset | |
|---|---|---|
| Sizing | Fixed steps, prose-sm to prose-2xl | Relative to the container, any size |
| Dark mode | A second palette with prose-invert | Your theme tokens flip on their own |
| Overrides | Modifiers like prose-a: | Plain utilities and CSS |
| Streaming | No guarantees for appended content | Appends never restyle earlier blocks |
| Distribution | npm plugin | One CSS file in your repo |
The :where() guard and the opt-out class (in the spirit of not-prose) come straight from the plugin.