

# Prose

Styles the bare HTML a markdown renderer emits (headings, paragraphs, lists, links, inline and fenced code, blockquotes, tables, rules) for use inside app UI: an agent reply in a chat bubble, a trace panel, a note, a description field.

Everything is relative to the surrounding font size, so `Prose` takes the size of whatever it sits in. Headings use the body font at a modest scale.

## Examples

### Compact, in a chat bubble

```tsx
import Markdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { ChatMessage, ChatMessageBubble, Prose, proseComponents } from '@var-ui/react';

<ChatMessage sender="assistant">
  <ChatMessageBubble>
    <Prose density="compact">
      <Markdown remarkPlugins={[remarkGfm]} components={proseComponents}>
        {reply}
      </Markdown>
    </Prose>
  </ChatMessageBubble>
</ChatMessage>
```

```astro
---
import { Prose } from '@var-ui/astro';
import { Content } from '../notes/release.md';
---

<Prose density="compact">
  <Content />
</Prose>
```

```html
<div data-density="compact" class="var-ui-prose">
  <h3>Build fixed</h3>
  <p>The failure came from a stale <code>dist</code> folder. I rebuilt core and the tests pass again:</p>
  <pre><code class="language-sh">vp run build
vp test run</code></pre>
  <ul>
    <li>2,642 tests passed</li>
    <li>See the <a href="#">CI run</a> for details</li>
  </ul>
</div>
```

## Density

`density` sets the vertical rhythm and heading scale:

- `compact`: chat bubbles, cards, table cells. Tight gaps; headings barely larger than text.
- `balanced` (default): side panels and detail views.
- `spacious`: reading views and long notes. Roomier gaps, larger headings, relaxed line height.

## Markdown renderers

`proseComponents` maps elements to Var UI components for any renderer that takes a `components` prop (react-markdown, MDX):

| Element                                     | Renders       | Why                                                                      |
| ------------------------------------------- | ------------- | ------------------------------------------------------------------------ |
| `pre` (fenced code)                         | `CodeBlock`   | Copy button; the language comes from the `language-*` class.             |
| `code` (inline)                             | `Code`        | Same chip as the rest of the app.                                        |
| `a`                                         | `Link`        | Client-side routing through `RouterProvider`.                            |
| `table`, `thead`, `tbody`, `tr`, `th`, `td` | `Table` parts | Horizontal scrolling, Table styles, and GFM column alignment as `align`. |

```tsx
import Markdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { Prose, proseComponents } from '@var-ui/react';

<Prose density="compact">
  <Markdown remarkPlugins={[remarkGfm]} components={proseComponents}>
    {reply}
  </Markdown>
</Prose>;
```

Override one entry by spreading: `components={{ ...proseComponents, a: MyLink }}`. The mapping is optional: without it, `Prose` still styles the bare elements, so HTML rendered on a server works as is.

## How it composes

`Prose`'s element rules live in the `base` [cascade layer](/theming/plain-css#cascade-layers-and-specificity), below `components`. A Var UI component inside `Prose` (mapped by `proseComponents` or placed by hand) always keeps its own styles, with no `data-not-prose` and no specificity contest with your own classes. You only need `data-not-prose` for markup that isn't a Var UI component.

## Opting out

Mark anything that shouldn't take prose styles with `data-not-prose`: a live demo, an embedded widget, a hand-built table. Prose skips the element and everything inside it. The element itself still gets the space between blocks, so it sits in the flow like any other block. Var UI components don't need it, because their own styles already win.

```tsx
<Prose>
  <Markdown>{intro}</Markdown>
  <div data-not-prose>
    <MyChart />
  </div>
</Prose>
```

To add your own element rules on top of prose, wrap them in `proseRules()` from `@var-ui/core` so they honour `data-not-prose` too.

## Astro

`Prose` from `@var-ui/astro` renders the same `<div>` and class; wrap rendered markdown (`<Content />`) in it. In plain HTML, put `class="var-ui-prose"` and `data-density="compact"` on the wrapper.

## Props

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| density | "balanced" \| "compact" \| "spacious" \| undefined | no | balanced | Vertical rhythm and heading scale. `compact` for chat bubbles and cards, `balanced` for panels, `spacious` for reading views. Font size is inherited either way. |

All native `<div>` attributes are passed through, and `ref` is the div.


> Also accepts all standard HTML attributes (ARIA attributes, event handlers, styles, …). Run `var-ui component prose --all-props` for the complete list.
