# Typography (prose)

> Wrapper that styles slotted long-form HTML (headings, lists, quotes, code, tables, figures) in the Haze type scale at 65 characters.

- Kind: ui · Category: Layout and media · Interactivity: none
- Install: `npx shadcn@latest add @haze/typography`
- File: `src/components/haze/ui/typography.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/typography

## Use when
- Rendering an article, doc page or changelog body from Markdown or a CMS as plain HTML
- Slotted markup you do not control, where classes cannot go on each element
- A narrow column that must wrap text, scroll wide code and tables inside themselves, and never widen the page

## Avoid when
- A title with an eyebrow and intro above a section; use section-heading
- Editing the content in the page; use rich-text-editor
- Markup you write yourself with a few elements; classes on the elements are simpler

## Alternatives
- [section-heading](https://hazeui.com/ui/section-heading.md)
- [rich-text-editor](https://hazeui.com/ui/rich-text-editor.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| size | `"sm" \| "base"` | "base" | no | Body size: 13 px or 15 px. Headings, code and table text scale with it. |
| measure | `boolean` | true | no | Caps the width at 65ch. Pass false when the parent column already sets the width. |
| lead | `boolean` | false | no | Sets the first paragraph larger and muted, as an introduction. |
| class | `string` |  | no | Extra classes on the wrapper, merged with tailwind-merge. |
| ...attributes | `HTML div attributes` |  | no | Passed to the wrapper: id, lang, aria-labelledby, data attributes. |

## Accessibility
- It only styles; the semantics come from the HTML you slot. Keep one heading level step at a time (h2, then h3) so the outline stays valid.
- Quotes are marked by indentation, italics and muted text, not by a colored stripe, so they hold up in high-contrast modes.
- Links are underlined and keep a visible focus outline, so they do not depend on color to be found.
- Code blocks and tables scroll inside their own box (overflow-x-auto), which keeps the page from scrolling sideways at 320 px; the scrolling box is reachable by keyboard when it overflows, so give a wide pre role="region", tabindex="0" and an aria-label. Tables are styled as scroll boxes with display: block, which can drop table semantics in Safari with VoiceOver, so wrap a wide table in a focusable role="region" container with an aria-label and let that container scroll.
- Headings carry scroll-margin so anchor links do not land under a sticky header.

## Agent prompts

### Install and use

Install the Haze UI component "Typography (prose)" with `npx shadcn@latest add @haze/typography`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Typography from "@/components/haze/ui/typography.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/typography.md

### Customize with real content

Adapt the Haze typography ui for our product. Replace the demo values of these props with our real content: size, measure, lead, class, ...attributes. Keep the layout, the heading level rules and these accessibility details: It only styles; the semantics come from the HTML you slot. Keep one heading level step at a time (h2, then h3) so the outline stays valid. Quotes are marked by indentation, italics and muted text, not by a colored stripe, so they hold up in high-contrast modes. Links are underlined and keep a visible focus outline, so they do not depend on color to be found. Code blocks and tables scroll inside their own box (overflow-x-auto), which keeps the page from scrolling sideways at 320 px; the scrolling box is reachable by keyboard when it overflows, so give a wide pre role="region", tabindex="0" and an aria-label. Tables are styled as scroll boxes with display: block, which can drop table semantics in Safari with VoiceOver, so wrap a wide table in a focusable role="region" container with an aria-label and let that container scroll. Headings carry scroll-margin so anchor links do not land under a sticky header. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using typography, check it fits: use it when rendering an article, doc page or changelog body from markdown or a cms as plain html; slotted markup you do not control, where classes cannot go on each element; a narrow column that must wrap text, scroll wide code and tables inside themselves, and never widen the page. Avoid it when a title with an eyebrow and intro above a section; use section-heading; editing the content in the page; use rich-text-editor; markup you write yourself with a few elements; classes on the elements are simpler. Alternatives: @haze/section-heading, @haze/rich-text-editor.

## Example requests that should lead here
- Wrap the rendered Markdown of this release note in the prose styles
- Show a changelog entry with a heading, list, quote and a small table in a narrow column
- Use the small size for a help-center article body

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Props {
  /** Size of the running text. Headings, code and tables scale with it. */
  size?: "sm" | "base";
  /** Caps the line length at about 65 characters. Pass false inside a column that already limits width. */
  measure?: boolean;
  /** Sets the first paragraph larger and muted, as an introduction. */
  lead?: boolean;
  class?: string;
  [key: string]: unknown;
}

const { size = "base", measure = true, lead = false, class: className, ...rest } = Astro.props;

const sizes = {
  sm: "text-[0.8125rem]/6 [&_h2]:text-lg/7 [&_h3]:text-base/6 [&_h4]:text-[0.8125rem]/5 [&_pre]:text-xs/5 [&_th]:text-xs/5 [&_td]:text-xs/5 [&>*+*]:mt-3.5",
  base: "text-[0.9375rem]/7 [&_h2]:text-xl/8 [&_h3]:text-[1.0625rem]/7 [&_h4]:text-[0.9375rem]/6 [&_pre]:text-[0.8125rem]/6 [&_th]:text-[0.8125rem]/5 [&_td]:text-[0.8125rem]/5 [&>*+*]:mt-4",
};

const classes = cn(
  "min-w-0 text-foreground",
  measure && "max-w-[65ch]",
  sizes[size],
  // headings
  "[&_h2]:font-semibold [&_h2]:tracking-tight [&_h3]:font-semibold [&_h3]:tracking-tight [&_h4]:font-semibold [&_h4]:tracking-tight",
  "[&>h2]:mt-10 [&>h3]:mt-8 [&>h4]:mt-6 [&>h2+*]:mt-3 [&>h3+*]:mt-2.5 [&>h4+*]:mt-2 [&_:where(h2,h3,h4)]:scroll-mt-20",
  // lead paragraph
  lead && "[&>p:first-child]:text-[1.0625rem]/7 [&>p:first-child]:text-muted-foreground",
  // inline text
  "[&_strong]:font-semibold [&_em]:italic",
  "[&_a]:rounded-xs [&_a]:text-foreground [&_a]:underline [&_a]:decoration-border-strong [&_a]:underline-offset-4 [&_a]:transition-colors [&_a]:duration-150 hover:[&_a]:decoration-foreground focus-visible:[&_a]:outline-2 focus-visible:[&_a]:outline-offset-1 focus-visible:[&_a]:outline-ring",
  "[&_:where(p,li,td,th,blockquote)]:wrap-break-word",
  // lists
  "[&_ul]:list-disc [&_ol]:list-decimal [&_:where(ul,ol)]:pl-5 [&_:where(ul,ol)]:marker:text-muted-foreground [&_li]:pl-1 [&_li+li]:mt-1.5 [&_li>:where(ul,ol)]:mt-1.5",
  // quote: indentation and muted italics, no stripe
  "[&_blockquote]:pl-4 [&_blockquote]:italic [&_blockquote]:text-muted-foreground [&_blockquote_p+p]:mt-3",
  // code
  "[&_:not(pre)>code]:rounded-sm [&_:not(pre)>code]:bg-muted [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:py-0.5 [&_:not(pre)>code]:font-mono [&_:not(pre)>code]:text-[0.875em] [&_:not(pre)>code]:font-medium",
  "[&_pre]:block [&_pre]:max-w-full [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:border [&_pre]:border-border [&_pre]:bg-muted [&_pre]:p-3.5 [&_pre]:font-mono [&_pre]:text-foreground [&_pre_code]:bg-transparent [&_pre_code]:p-0",
  "[&_kbd]:rounded-sm [&_kbd]:border [&_kbd]:border-border [&_kbd]:bg-card [&_kbd]:px-1 [&_kbd]:py-0.5 [&_kbd]:font-mono [&_kbd]:text-[0.8125em] [&_kbd]:font-medium [&_kbd]:shadow-key",
  // rule
  "[&_hr]:my-8 [&_hr]:border-0 [&_hr]:border-t [&_hr]:border-border",
  // table: made a block so it scrolls inside the column instead of widening the page
  "[&_table]:block [&_table]:max-w-full [&_table]:overflow-x-auto [&_table]:border-collapse [&_table]:tabular-nums",
  "[&_th]:border-b [&_th]:border-border-strong [&_th]:px-3 [&_th]:py-2 [&_th]:text-left [&_th]:font-medium [&_th]:whitespace-nowrap",
  "[&_td]:border-b [&_td]:border-border [&_td]:px-3 [&_td]:py-2 [&_td]:align-top [&_tr:last-child_td]:border-b-0",
  // figures
  "[&_img]:h-auto [&_img]:max-w-full [&_img]:rounded-lg [&_figure]:mt-6 [&_figure_img]:w-full [&_figcaption]:mt-2 [&_figcaption]:text-xs/5 [&_figcaption]:text-muted-foreground",
  // first and last children sit flush with the wrapper
  "[&>:first-child]:mt-0",
  className,
);
---

<div class={classes} {...rest}><slot /></div>
```
