# Prose (/docs/prose)





`Prose` is a wrapper for HTML that your app renders but doesn't write element by element: a project subject, an announcement or a changelog that comes out of a markdown renderer or a CMS. It isn't a markdown parser. Your app turns the markdown into HTML, and `Prose` styles the plain elements inside it to match the kit.

```tsx
import { Prose } from "@42-central/ui-react/prose";
import "@42-central/ui-react/prose/styles.css";

<Prose dangerouslySetInnerHTML={{ __html: sanitize(html) }} />
<Prose>{renderMarkdown(source)}</Prose>
```

The element styles ship as a separate stylesheet. Import `@42-central/ui-react/prose/styles.css` once, next to `theme.css`. Without it, `Prose` renders unstyled HTML.

## Playground [#playground]

<story.Playground />

## A project subject [#a-project-subject]

A subject rendered from markdown, passed as an HTML string. The headings use [`Title`](/docs/title)'s scale, inline code looks like [`Code`](/docs/code), the code block has [`CodeBlock`](/docs/code-block)'s frame, the table looks like [`Table`](/docs/table), and the highlight, the keys and the links look like [`Mark`](/docs/mark), [`Kbd`](/docs/kbd) and [`Anchor`](/docs/anchor).

<Preview code="`<Prose measure dangerouslySetInnerHTML={{ __html: subjectHtml }} />`">
  <ProseSubjectDemo />
</Preview>

## What it styles [#what-it-styles]

| Element                                | Looks like                                                                                                                                               |
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `h1` to `h6`                           | `Title` at the same level: `h1` is `4xl`, `h6` is `md`                                                                                                   |
| `p`, `strong`, `em`                    | Body text in the primary text colour                                                                                                                     |
| `a`                                    | `Anchor`: the same `--btn-link-*` colours, underline and focus ring                                                                                      |
| `ul`, `ol`, nested lists               | Disc, circle and square bullets; numbers, letters and roman numerals. An `ol` or `ul` with a `type` (`1`, `a`, `i`, `disc`, `circle`, `square`) keeps it |
| Task lists                             | GitHub's `<li><input type="checkbox">` items, drawn like `Checkbox`                                                                                      |
| `blockquote`                           | A hairline on the start side, in the secondary text colour                                                                                               |
| `code`                                 | `Code`'s neutral pill, at the size of the text around it                                                                                                 |
| `pre`                                  | `CodeBlock`'s frame, without highlighting. It reads left to right in RTL text, like `CodeBlock`                                                          |
| `table`                                | `Table`'s surface, header and row lines. Markdown's column `align` is kept                                                                               |
| `img`, `video`, `figure`, `figcaption` | `Image`'s radius and `Figure`'s caption                                                                                                                  |
| `hr`                                   | `Divider`'s hairline                                                                                                                                     |
| `mark`                                 | `Mark`'s yellow highlight                                                                                                                                |
| `kbd`                                  | `Kbd`'s key cap. In `<kbd><kbd>Ctrl</kbd>+<kbd>K</kbd></kbd>`, only the inner keys are caps                                                              |
| `details`, `summary`                   | A quiet surface with a chevron that mirrors in RTL                                                                                                       |
| `dl`, footnotes                        | Bold terms; GitHub's footnotes section in small secondary text                                                                                           |

<Preview code="`<Prose measure dangerouslySetInnerHTML={{ __html: elementsHtml }} />`">
  <ProseElementsDemo />
</Preview>

## Size [#size]

`size` sets the body text to `sm` (14px), `md` (16px, the default) or `lg` (18px). Headings, spacing, code and tables scale with it. At `md`, each heading is exactly the size of a `Title` of the same level.

<Preview align="block" code="&#x22;<Prose size=\&#x22;sm\&#x22;>…</Prose>\n<Prose size=\&#x22;md\&#x22;>…</Prose>\n<Prose size=\&#x22;lg\&#x22;>…</Prose>&#x22;">
  <ProseSizesDemo />
</Preview>

## Measure [#measure]

`measure` caps the line length at 65 characters, a comfortable reading width. It's off by default, because the layout around `Prose` usually decides how wide it is. For another width, pass a `max-w-*` class instead.

## Kit components inside Prose [#kit-components-inside-prose]

`Prose` only styles plain elements. A kit component inside it keeps its own look:

* The styles are in CSS's `components` layer, under Tailwind's `utilities`. Any property a component's classes set wins over Prose's.
* Every selector is a bare element name, so any class beats it.

A kit component can still pick up properties it doesn't set itself, such as the margins Prose gives a `<p>`. To opt a block out completely, give it the `not-prose` class. Prose doesn't style that element or anything inside it.

<Preview code="&#x22;<Prose measure>\n  <p>Prose styles the plain elements around this card:</p>\n  <Card className=\&#x22;not-prose\&#x22;>\n    <p className=\&#x22;font-medium\&#x22;>Deadline</p>\n    <p className=\&#x22;text-sm text-black/60 dark:text-white/60\&#x22;>\n      Friday, 23:42. <Badge color=\&#x22;orange\&#x22;>3 days left</Badge>\n    </p>\n  </Card>\n  <p>The card has <code>className=\&#x22;not-prose\&#x22;</code>, …</p>\n</Prose>&#x22;">
  <ProseNotProseDemo />
</Preview>

`not-prose` only counts between the `Prose` and the element. A `Prose` inside someone else's `not-prose`, such as this site's demo frames, is still styled.

If you render markdown with React (MDX, `react-markdown`), you can also map elements to kit components, for example `a` to `Anchor` so links go through your router. They keep their own styles inside `Prose`.

## Customising [#customising]

To restyle one element, put a descendant class on `Prose`. It wins over the default:

```tsx
<Prose className="[&_h2]:text-brand-500 [&_table]:text-xs">…</Prose>
```

The colours are custom properties on the root, so you can change one role for every element that uses it: `--prose-body`, `--prose-heading`, `--prose-quote`, `--prose-muted`, `--prose-hairline`, `--prose-code-bg` and the rest listed at the top of `styles.css`. Links read `--btn-link-text` and `--btn-link-hover`, so retheming those changes `Anchor`, `<Button variant="link">` and Prose's links together.

## Security [#security]

`Prose` doesn't sanitize anything. HTML passed through `dangerouslySetInnerHTML` runs as is, scripts and event handlers included. Sanitize anything that a user can write (a subject, a comment, an announcement) on the server, with a library such as DOMPurify or `rehype-sanitize`, before you pass it in.

## Server components [#server-components]

`Prose` is a server component: it has no `"use client"` and no state. It renders a `<div>`, or with `asChild`, your own element (an `<article>`, say).

## Browser support [#browser-support]

The styles use CSS [`@scope`](https://developer.mozilla.org/docs/Web/CSS/@scope), supported in Chrome 118, Safari 17.4 and Firefox 146 or later. Headings trim their leading with `text-box-trim` like `Title`; browsers without it keep normal leading.

## Anatomy [#anatomy]

`Prose` is a single part: one element that carries the hooks the stylesheet scopes to.

```tsx
<div data-prose data-size="md" data-measure data-testid="subject">
  {/* your HTML */}
  <div className="not-prose">{/* left alone */}</div>
</div>
```

`testId` renders as `data-testid` on that element. See [Testing](/docs/testing). `data-measure` is present only when `measure` is on.

## API [#api]

<TypeTable
  type="{
  size: {
    type: '&#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22;',
    default: '&#x22;md&#x22;',
    description: &#x22;Body text size. Headings, spacing and code scale with it; at md, headings match Title.&#x22;,
  },
  measure: {
    type: &#x22;boolean&#x22;,
    default: &#x22;false&#x22;,
    description: &#x22;Caps the line length at 65 characters.&#x22;,
  },
  asChild: {
    type: &#x22;boolean&#x22;,
    default: &#x22;false&#x22;,
    description: &#x22;Renders your single child element (an <article>, say) as the root.&#x22;,
  },
  dangerouslySetInnerHTML: {
    type: &#x22;{ __html: string }&#x22;,
    description: &#x22;React's own prop, for an HTML string. Sanitize it first.&#x22;,
  },
  testId: {
    type: &#x22;string&#x22;,
    description: &#x22;Renders as data-testid on the root. See [Testing](/docs/testing).&#x22;,
  },
}"
/>

Every other prop is forwarded to the root `<div>`.

## Accessibility [#accessibility]

* `Prose` adds no roles. The HTML keeps its own semantics: headings, lists, tables and `details` work with assistive technology as they would anywhere else. Pass `asChild` with an `<article>` to make the document a landmark-like region of its own.
* The document outline is yours. Prose styles an `h2` like a level-2 `Title`, so render headings at the right level rather than picking them by size.
* Links are underlined, so they don't rely on colour alone ([WCAG 1.4.1](https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html)), and they and `summary` show the kit's focus ring.
* Task list checkboxes stay real, disabled `<input>`s, so screen readers announce them as checked or not checked.
* Images need their `alt` text in the HTML. Prose can't add it.
