# Markdown

Prose styling wrapper for rendered markdown/HTML assistant output.

- Category: AI & Agents
- Page: https://wunderui.com/components/markdown
- Tier: Core and Pro

## Install

Markdown ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { Markdown } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { Markdown } from "@wunderui/react"

export function Answer() {
  return (
    <Markdown>
      <h2>Q3 summary</h2>
      <p>Revenue grew <code>12%</code> quarter over quarter to $1,842,000.</p>
      <ul>
        <li>New customers: 1,204</li>
        <li>Churn: 1.8%</li>
      </ul>
    </Markdown>
  )
}
```

Expected result: You see a bold heading, a paragraph in a lighter text colour with 12% in a small chip, and a bulleted list with two items.

## When to use

### Use Markdown for

- An assistant reply with headings, paragraphs, lists, links and inline code
- Streamed text that a parser re-renders on every update
- Short release notes or help text that comes from a Markdown source

### Use something else

- [Code Block](https://wunderui.com/components/code-block) for source code with a language label, a copy button and sideways scrolling
- [Table](https://wunderui.com/components/table) for data in rows and columns that people sort, select or scan
- [Chat Message](https://wunderui.com/components/chat-message) for the bubble, the avatar and the role around a reply

## Keyboard

Markdown has no interactive part of its own. Links inside are native anchors, so the browser handles focus and activation.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the next or previous link in the text, in reading order. |
| `Enter` | Follows the focused link. |

Text is not focusable. A link shows the browser focus ring unless the parser adds one.

## Behavior

What the component does and does not do with Markdown, links, markup and streaming.

- **A wrapper, not a parser:** Markdown renders its children inside a styled div. It does not read a Markdown string, so passing one shows raw text: parse it first and pass the elements.
- **What is styled:** Styled: h1, h2, p, a, code, ul and ol. Other headings, tables, quotes, rules, images, pre and strong follow the browser and Tailwind defaults.
- **Tables:** A table is drawn without borders or padding. Pass classes on Markdown that target th and td, and one string styles every table in the answer.
- **Code:** The chip rule matches only inline code, so a CodeBlock inside the box keeps its own look.
- **Links:** Links are only styled. The component does not check URLs, add target or rel, or open new tabs, and a javascript: link stays clickable, so check links in the parser.
- **Sanitization:** The component sanitizes nothing, so safety lives in the parser. react-markdown builds React elements, escapes raw HTML unless you add rehype-raw, and drops unsafe URL schemes by default.
- **Streaming:** Re-render the parser with the longer text on every update. Wrap the reply in a log region and set aria-busy while it grows, so a screen reader reads it once.
- **Live region:** Markdown announces nothing itself. The log region around the conversation announces what is added.
- **Motion:** None, so there is nothing to reduce. If you animate a reply in, use opacity and transform with the entrance timing and switch it off for reduced motion.

## Anatomy

- `Markdown`: A div that stacks its children in a column with an 8 px gap and sets 14 px text in the foreground colour. It parses nothing: it styles the elements you pass in.
- `Heading`: An h1 (18 px, bold) or an h2 (16 px, bold). Deeper headings have no rule and look like body text.
- `Inline code`: Any inline code (not inside a pre): a muted chip with 4 px corners and 12 px text. Code inside a CodeBlock keeps its own look.
- `Link`: An anchor in the link colour, underlined. It sets no target or rel; add them in the parser.
- `Paragraph`: A paragraph in the secondary text colour, a step lighter than headings and list items.
- `List`: A bulleted or numbered list, indented 20 px. List items keep the foreground colour.

## Best practices

### When to use

- Use Markdown to give an agent answer consistent typography once a parser has turned it into elements. For source code with a language label and copy button, use Code Block.

### Do

- Parse first, then pass the elements as children. A raw Markdown string stays raw.
- Render model text with a parser that builds React elements, such as react-markdown, never with dangerouslySetInnerHTML. Model output and tool results are data and can contain markup.
- Check every link in the parser: allow http, https and mailto, show anything else as plain text, and add rel noopener noreferrer to links that open a new tab.
- Put a CodeBlock in the answer for multi-line code. The chip style only reaches inline code, so the block keeps its own look.
- Style tables with a class on Markdown, because it has no rules for table, th and td.

### Don't

- Don't expect headings below h2, block quotes, images or tables to be styled. Only the listed elements have rules.
- Don't override link or paragraph colour with hex values. The tokens follow light and dark.
- Don't set aria-live on Markdown to announce a streaming reply. Put a log region around the conversation and set aria-busy while the text grows.

## API reference

### Markdown

| Prop | Type | Default | Description |
|---|---|---|---|
| children* | React.ReactNode |  | The elements to style, already parsed: headings, paragraphs, lists, links and inline code. A raw Markdown string is shown as it is. |
| citationLabel | (n: number) => string |  | Accessible name of a citation button made by `onCite`, for example the source title. Defaults to "Source n". |
| className | string |  | Extra classes for the box. Arbitrary variants such as `[&_table]:w-full` or `[&_pre_code]:p-0` reach the elements inside, which is how you style a table or reset the chip on the code of a CodeBlock. |
| onCite | (n: number) => void |  | Makes every [n] marker a button that calls this with the number. |
| renderCitation | (n: number) => React.ReactNode |  |  |

## Examples

### Table: no rules of its own, a className adds them

### A string with clickable citations

## In context

### Streaming: partial Markdown rendered while the reply grows

Press Stream again. Unclosed code fences already render as code blocks and unclosed bold stays plain until it closes, and a screen reader reads the reply once, when complete.

### Text from the model: links are checked, raw HTML shows as text

Model output is data. Only http, https and mailto links become links, other links show their label as plain text, and raw markup is never rendered.

### Reply: a table, bold text and a code block in an assistant message

Markdown carries the typography, a class carries the table, and fenced code goes to a Code Block. Tab reaches the copy button, then the code area, then the four actions.

## For AI agents

`get_component("markdown")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
