Streamdown
Streaming-optimized React Markdown renderer. Drop-in replacement for react-markdown with built-in streaming support, security, and interactive controls.
Quick Setup
1. Install
npm install streamdown
Optional plugins (install only what's needed):
npm install @streamdown/code @streamdown/mermaid @streamdown/math @streamdown/cjk
2. Configure Tailwind CSS (Required)
This is the most commonly missed step. Streamdown uses Tailwind for styling and the dist files must be scanned.
Tailwind v4 — add to globals.css:
@source "../node_modules/streamdown/dist/*.js";
Add plugin @source lines only for packages you have installed (omitting uninstalled plugins avoids Tailwind errors). See plugin pages for exact paths:
- Code:
@source "../node_modules/@streamdown/code/dist/*.js";
- CJK:
@source "../node_modules/@streamdown/cjk/dist/*.js";
- Math:
@source "../node_modules/@streamdown/math/dist/*.js";
- Mermaid:
@source "../node_modules/@streamdown/mermaid/dist/*.js";
Tailwind v3 — add to tailwind.config.js:
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/streamdown/dist/*.js",
],
};
3. Basic Usage
import { Streamdown } from 'streamdown';
<Streamdown>{markdown}</Streamdown>
4. With AI Streaming (Vercel AI SDK)
'use client';
import { useChat } from '@ai-sdk/react';
import { Streamdown } from 'streamdown';
import { code } from '@streamdown/code';
export default function Chat() {
const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();
return (
<>
{messages.map((msg, i) => (
<Streamdown
key={msg.id}
plugins={{ code }}
caret="block"
isAnimating={isLoading && i === messages.length - 1 && msg.role === 'assistant'}
>
{msg.content}
</Streamdown>
))}
<form
<input value={input} disabled={isLoading} />
</form>
</>
);
}
5. Static Mode (Blogs, Docs)
<Streamdown mode="static" plugins={{ code }}>
{content}
</Streamdown>
Key Props
| Prop |
Type |
Default |
Purpose |
children |
string |
— |
Markdown content |
mode |
"streaming" | "static" |
"streaming" |
Rendering mode |
plugins |
{ code?, mermaid?, math?, cjk? } |
— |
Feature plugins |
isAnimating |
boolean |
false |
Streaming indicator |
caret |
"block" | "circle" |
— |
Cursor style |
components |
Components |
— |
Custom element overrides |
controls |
boolean | object |
true |
Interactive buttons |
linkSafety |
LinkSafetyConfig |
{ enabled: true } |
Link confirmation modal |
shikiTheme |
[light, dark] |
['github-light', 'github-dark'] |
Code themes |
className |
string |
— |
Container class |
allowedElements |
string[] |
all |
Tag names to allow |
disallowedElements |
string[] |
[] |
Tag names to disallow |
allowElement |
AllowElement |
— |
Custom element filter |
unwrapDisallowed |
boolean |
false |
Keep children of disallowed elements |
skipHtml |
boolean |
false |
Ignore raw HTML |
urlTransform |
UrlTransform |
defaultUrlTransform |
Transform/sanitize URLs |
For full API reference, see references/api.md.
Plugin Quick Reference
| Plugin |
Package |
Purpose |
| Code |
@streamdown/code |
Syntax highlighting (Shiki, 200+ languages) |
| Mermaid |
@streamdown/mermaid |
Diagrams (flowcharts, sequence, etc.) |
| Math |
@streamdown/math |
LaTeX via KaTeX (requires CSS import) |
| CJK |
@streamdown/cjk |
Chinese/Japanese/Korean text support |
Math requires CSS:
import 'katex/dist/katex.min.css';
For plugin configuration details, see references/plugins.md.
References
Use these for deeper implementation details:
- references/api.md — Complete props, types, and interfaces
- references/plugins.md — Plugin setup, configuration, and customization
- references/styling.md — CSS variables, data attributes, custom components, theme examples
- references/security.md — Hardening, link safety, custom HTML tags, production config
- references/features.md — Carets, remend, static mode, controls, GFM, memoization, troubleshooting
Example Configurations
Copy and adapt from assets/examples/:
- basic-streaming.tsx — Minimal AI chat with Vercel AI SDK
- with-caret.tsx — Streaming with block caret cursor
- full-featured.tsx — All plugins, carets, link safety, controls
- static-mode.tsx — Blog/docs rendering
- custom-security.tsx — Strict security for AI content
Common Gotchas
- Tailwind styles missing — Add
@source directive or content entry for node_modules/streamdown/dist/*.js
- Math not rendering — Import
katex/dist/katex.min.css
- Caret not showing — Both
caret prop AND isAnimating={true} are required
- Copy buttons during streaming — Disabled automatically when
isAnimating={true}
- Link safety modal appearing — Enabled by default; disable with
linkSafety={{ enabled: false }}
- Shiki warning in Next.js — Install
shiki explicitly, add to transpilePackages
allowedTags not working — Only works with default rehype plugins
- Math uses
$$ not $ — Single dollar is disabled by default to avoid currency conflicts
1---2name: streamdown3description: Implement, configure, and customize Streamdown — a streaming-optimized React Markdown renderer with syntax highlighting, Mermaid diagrams, math rendering, and CJK support. Use when working with Streamdown setup, configuration, plugins, styling, security, or integration with AI streaming (e.g., Vercel AI SDK). Triggers on: (1) Installing or setting up Streamdown, (2) Configuring plugins (code, mermaid, math, cjk), (3) Styling or theming Streamdown output, (4) Integrating with AI chat/streaming, (5) Configuring security, link safety, or custom HTML tags, (6) Using carets, static mode, or custom components, (7) Troubleshooting Tailwind, Shiki, or Vite issues.4---5
6# Streamdown
7
8Streaming-optimized React Markdown renderer. Drop-in replacement for `react-markdown` with built-in streaming support, security, and interactive controls.
9
10## Quick Setup
11
12### 1. Install
13
14```bash
15npm install streamdown
16```
17
18Optional plugins (install only what's needed):
19```bash
20npm install @streamdown/code @streamdown/mermaid @streamdown/math @streamdown/cjk
21```
22
23### 2. Configure Tailwind CSS (Required)
24
25**This is the most commonly missed step.** Streamdown uses Tailwind for styling and the dist files must be scanned.
26
27**Tailwind v4** — add to `globals.css`:
28```css
29@source "../node_modules/streamdown/dist/*.js";
30```
31
32Add plugin `@source` lines **only for packages you have installed** (omitting uninstalled plugins avoids Tailwind errors). See plugin pages for exact paths:
33- Code: `@source "../node_modules/@streamdown/code/dist/*.js";`
34- CJK: `@source "../node_modules/@streamdown/cjk/dist/*.js";`
35- Math: `@source "../node_modules/@streamdown/math/dist/*.js";`
36- Mermaid: `@source "../node_modules/@streamdown/mermaid/dist/*.js";`
37
38
39**Tailwind v3** — add to `tailwind.config.js`:
40```js
41module.exports = {
42 content: [
43 "./app/**/*.{js,ts,jsx,tsx,mdx}",
44 "./node_modules/streamdown/dist/*.js",
45 ],
46};
47```
48
49### 3. Basic Usage
50
51```tsx
52import { Streamdown } from 'streamdown';
53
54<Streamdown>{markdown}</Streamdown>
55```
56
57### 4. With AI Streaming (Vercel AI SDK)
58
59```tsx
60'use client';
61import { useChat } from '@ai-sdk/react';
62import { Streamdown } from 'streamdown';
63import { code } from '@streamdown/code';
64
65export default function Chat() {
66 const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();
67
68 return (
69 <>
70 {messages.map((msg, i) => (
71 <Streamdown
72 key={msg.id}
73 plugins={{ code }}
74 caret="block"
75 isAnimating={isLoading && i === messages.length - 1 && msg.role === 'assistant'}
76 >
77 {msg.content}
78 </Streamdown>
79 ))}
80 <form onSubmit={handleSubmit}>
81 <input value={input} onChange={handleInputChange} disabled={isLoading} />
82 </form>
83 </>
84 );
85}
86```
87
88### 5. Static Mode (Blogs, Docs)
89
90```tsx
91<Streamdown mode="static" plugins={{ code }}>
92 {content}
93</Streamdown>
94```
95
96## Key Props
97
98| Prop | Type | Default | Purpose |
99|------|------|---------|---------|
100| `children` | `string` | — | Markdown content |
101| `mode` | `"streaming" \| "static"` | `"streaming"` | Rendering mode |
102| `plugins` | `{ code?, mermaid?, math?, cjk? }` | — | Feature plugins |
103| `isAnimating` | `boolean` | `false` | Streaming indicator |
104| `caret` | `"block" \| "circle"` | — | Cursor style |
105| `components` | `Components` | — | Custom element overrides |
106| `controls` | `boolean \| object` | `true` | Interactive buttons |
107| `linkSafety` | `LinkSafetyConfig` | `{ enabled: true }` | Link confirmation modal |
108| `shikiTheme` | `[light, dark]` | `['github-light', 'github-dark']` | Code themes |
109| `className` | `string` | — | Container class |
110| `allowedElements` | `string[]` | all | Tag names to allow |
111| `disallowedElements` | `string[]` | `[]` | Tag names to disallow |
112| `allowElement` | `AllowElement` | — | Custom element filter |
113| `unwrapDisallowed` | `boolean` | `false` | Keep children of disallowed elements |
114| `skipHtml` | `boolean` | `false` | Ignore raw HTML |
115| `urlTransform` | `UrlTransform` | `defaultUrlTransform` | Transform/sanitize URLs |
116
117For full API reference, see [references/api.md](references/api.md).
118
119## Plugin Quick Reference
120
121| Plugin | Package | Purpose |
122|--------|---------|---------|
123| Code | `@streamdown/code` | Syntax highlighting (Shiki, 200+ languages) |
124| Mermaid | `@streamdown/mermaid` | Diagrams (flowcharts, sequence, etc.) |
125| Math | `@streamdown/math` | LaTeX via KaTeX (requires CSS import) |
126| CJK | `@streamdown/cjk` | Chinese/Japanese/Korean text support |
127
128**Math requires CSS:**
129```tsx
130import 'katex/dist/katex.min.css';
131```
132
133For plugin configuration details, see [references/plugins.md](references/plugins.md).
134
135## References
136
137Use these for deeper implementation details:
138
139- **[references/api.md](references/api.md)** — Complete props, types, and interfaces
140- **[references/plugins.md](references/plugins.md)** — Plugin setup, configuration, and customization
141- **[references/styling.md](references/styling.md)** — CSS variables, data attributes, custom components, theme examples
142- **[references/security.md](references/security.md)** — Hardening, link safety, custom HTML tags, production config
143- **[references/features.md](references/features.md)** — Carets, remend, static mode, controls, GFM, memoization, troubleshooting
144
145## Example Configurations
146
147Copy and adapt from `assets/examples/`:
148
149- **[basic-streaming.tsx](assets/examples/basic-streaming.tsx)** — Minimal AI chat with Vercel AI SDK
150- **[with-caret.tsx](assets/examples/with-caret.tsx)** — Streaming with block caret cursor
151- **[full-featured.tsx](assets/examples/full-featured.tsx)** — All plugins, carets, link safety, controls
152- **[static-mode.tsx](assets/examples/static-mode.tsx)** — Blog/docs rendering
153- **[custom-security.tsx](assets/examples/custom-security.tsx)** — Strict security for AI content
154
155## Common Gotchas
156
1571. **Tailwind styles missing** — Add `@source` directive or `content` entry for `node_modules/streamdown/dist/*.js`
1582. **Math not rendering** — Import `katex/dist/katex.min.css`
1593. **Caret not showing** — Both `caret` prop AND `isAnimating={true}` are required
1604. **Copy buttons during streaming** — Disabled automatically when `isAnimating={true}`
1615. **Link safety modal appearing** — Enabled by default; disable with `linkSafety={{ enabled: false }}`
1626. **Shiki warning in Next.js** — Install `shiki` explicitly, add to `transpilePackages`
1637. **`allowedTags` not working** — Only works with default rehype plugins
1648. **Math uses `$$` not `$`** — Single dollar is disabled by default to avoid currency conflicts