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