# Markdown (/docs/agent-ui/components/markdown)

Use Markdown for the text of an assistant's reply. Pass the text so far as `source`, and it parses only the blocks that changed, so a long answer costs no more per chunk than a short one.

<Example caption="Press the copy button above the code or the table to copy it, or the wrap button to wrap long lines.">
<h />

```tsx
import { Markdown } from "@/components/ui/markdown";

const source = `### Retry with backoff

Wait a little longer after each failure, and give up after a few tries. Retry only **idempotent** requests.

\`\`\`ts
await sleep(2 ** attempt * 250);
\`\`\`

| Attempt | Delay |
| ------: | ----: |
| 1 | 250 ms |
| 2 | 500 ms |
| 3 | 1 s |

> Read the \`Retry-After\` header first when the server sends one.
`;

export default function MarkdownExample() {
  return <Markdown source={source} />;
}
```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/markdown
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/markdown-web
```

## Usage [#usage]

### Streaming [#streaming]

Set `streaming` while the reply is still arriving, and pass the whole text each time it grows:

```tsx
<Markdown source={text} streaming={status === "streaming"} />
```

While it streams, the last block is repaired before it renders, so an unclosed `**` or link shows as formatted text instead of flashing its markup. A block is final once more text follows it, and final blocks don't render again. Turn `streaming` off when the reply ends, and the last block becomes final too.

### What It Renders [#what-it-renders]

Markdown follows GitHub Flavored Markdown: headings, paragraphs, emphasis, strikethrough, quotes, lists, task lists, links, images, rules, tables and fenced code. Fenced code renders in a [Code Block](./code-block.mdx) labeled "Code", and tables in a [Markdown Table](./markdown-table.mdx) labeled "Table", each with its own buttons.

Raw HTML shows as text. Links and images keep relative, `http`, `https` and `mailto` URLs; any other URL renders as its text, with no link.

### Highlighting [#highlighting]

No highlighter ships with Markdown. Pass a `highlight` function and every code block uses it to color its code; [Code Block](./code-block.mdx#highlighting) explains what it returns.

## API Reference [#api-reference]

### MarkdownOptions

| Prop         | Type                          | Description                                                                                                             |
| ------------ | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `source?`    | `string \| undefined`         | The markdown to show, so far. Appending parses only the blocks that changed.                                            |
| `streaming?` | `boolean \| undefined`        | Whether `source` is still growing, so the last block is repaired before it renders. Default: `false`                    |
| `highlight?` | `Highlight \| undefined`      | Passed to each code block to color its code. A new function doesn't color code already shown again.                     |
| `engine?`    | `MarkdownEngine \| undefined` | Parses `source`, read once when the view mounts; pass your own to read its `stats()`. Default: `createMarkdownEngine()` |

### Agent [#agent]

Markdown has no role, so an agent connected with `createAgent` sees it by kind, with no name and no actions of its own. The code blocks and tables inside it show up as their own components, with their actions.

<Caption>
Runs in React and Web Components. On `<kind-markdown>`, `source` and `streaming` are attributes, and `highlight` and `engine` are properties you set from script.
</Caption>