# Markdown

> Markdown rendering for AI answers. Handles streaming without half-typed syntax, tables you can copy and inline citations.

Canonical: https://hextaui.com/blocks/markdown
Last updated: 2026-10-29

## Overview

Models answer in Markdown, and they write it a token at a time. A plain renderer flashes raw asterisks, half-built tables and unclosed code fences while it streams. Markdown completes unfinished syntax as it goes and paces the text like the Streaming block, so formatting appears in place.

Each element is built from the rest of HextaUI. Code fences become Code Blocks, GitHub callouts like [!NOTE] use Alert, task lists use read-only Checkboxes, and tables scroll sideways with a menu to copy them as Markdown or CSV. Pass sources and [1] becomes a citation chip, while marks inside code are left alone.

Headings get ids from their text, with an optional link icon to share them. Images load lazily with a placeholder and caption, footnotes link back to their mark, external links open in a new tab and say so, and text direction is detected per block. It works as well for READMEs and changelogs as for streamed answers.

## Installation

### Step 1: Get HextaUI Pro

One payment unlocks every block, including future ones. [See pricing](https://hextaui.com/pricing).

### Step 2: Add the Pro registry to components.json

```json title="components.json"
{
  "registries": {
    "@hextaui-pro": {
      "url": "https://hextaui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
      }
    }
  }
}
```

### Step 3: Add your token

Create a token on your [account page](https://hextaui.com/account) and put it in `.env.local` as `HEXTAUI_PRO_TOKEN`.

### Step 4: Add the block

```bash
npx shadcn@latest add @hextaui-pro/markdown
```

## Usage

### With the AI SDK

Render each text part of a useChat message, with source-url parts as its sources. The part’s state tells Markdown when the model is still writing.

```tsx
"use client"

import type { UIMessage } from "ai"

import { Markdown } from "@/components/blocks/markdown/markdown"

export function AssistantMessage({ message }: { message: UIMessage }) {
  const sources = message.parts.flatMap((part) =>
    part.type === "source-url"
      ? [{ id: part.sourceId, url: part.url, title: part.title ?? part.url }]
      : []
  )

  return message.parts.map((part, index) =>
    part.type === "text" ? (
      <Markdown
        key={index}
        text={part.text}
        streaming={part.state === "streaming"}
        sources={sources}
      />
    ) : null
  )
}
```

### Static content

Pass a string as children for READMEs, changelogs or saved answers. Set anchors to give headings a link people can share.

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

const changelog = `## 2.4.0

> [!NOTE]
> Requires React 19.

- [x] Faster cold starts
- [x] Copy tables as CSV
- [ ] Offline mode`

export function Changelog() {
  return <Markdown anchors size="base">{changelog}</Markdown>
}
```

## Anatomy

The parts you compose, from the outside in.

| Part | Description |
| --- | --- |
| `Markdown` | The renderer. Takes a string and handles pacing, parsing and every element. |
| `MarkdownTable` | A scrollable table with the copy menu. |
| `MarkdownAlert` | A callout for [!NOTE] and the other GitHub alert types. |
| `MarkdownHeading` | A heading with an id and optional anchor link. |
| `MarkdownImage` | An image with loading, error and caption states. |

## API reference

### Markdown

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `text` | `string` | – | The Markdown so far. You can pass it as children instead. |
| `streaming` | `boolean` | `false` | Paces the text, shows the caret and completes unfinished syntax. |
| `smooth` | `boolean` | `true` | Turn pacing off to render text exactly as received. |
| `sources` | `Source[]` | `[]` | Turns [1] into a chip for sources[0], and so on. Without sources, [1] stays plain text. |
| `size` | `"sm" \| "base"` | `"sm"` | Text size. Use sm in chat and base for articles. |
| `anchors` | `boolean` | `false` | Show a link icon on headings. |
| `components` | `Components` | – | Override any element, such as a or img. Keep the object stable, for example outside the component, so blocks don’t remount. |
| `className` | `string` | – | Classes for the wrapper. |

## Keyboard

| Key | Action |
| --- | --- |
| `Tab` | Moves through links, citations, heading anchors, table copy menus and code block actions in reading order. |
| `Enter` | Opens a link, or the copy menu on a table. |
| `↑` `↓` | Moves between Copy as Markdown and Copy as CSV. |

## Accessibility

- The wrapper is marked aria-busy while it streams, so screen readers wait for the text to settle.
- Callouts use role=note with their type as the label, instead of announcing like live alerts.
- Task list checkboxes are read-only and skipped by Tab, so they read as state rather than controls.
- External links say “opens in a new tab”, citation chips are named after their source, and heading anchors are named “Link to …”.
- Images keep their alt text, and tables keep their header cells for screen reader navigation.
- With reduced motion, the caret stops pulsing and images appear without fading.

## Built with

The free HextaUI components Markdown is made from. Each one installs on its own.

- [Alert](https://hextaui.com/docs/alert) - Inline messages for status and feedback, with a neutral surface, a colored icon and a dismiss that collapses smoothly.
- [Button](https://hextaui.com/docs/button) - Buttons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- [Checkbox](https://hextaui.com/docs/checkbox) - A checkbox whose check draws in, with indeterminate parents, groups and labels that share its hover.
- [Dropdown menu](https://hextaui.com/docs/dropdown-menu) - A menu of actions and options behind a button, with groups, submenus, checkbox and radio items, and shortcuts.

## Code

4 files, added to components/blocks/markdown.
