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";
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---56# Streamdown78Streaming-optimized React Markdown renderer. Drop-in replacement for `react-markdown` with built-in streaming support, security, and interactive controls.910## Quick Setup1112### 1. Install1314```bash15npm install streamdown16```1718Optional plugins (install only what's needed):19```bash20npm install @streamdown/code @streamdown/mermaid @streamdown/math @streamdown/cjk21```2223### 2. Configure Tailwind CSS (Required)2425**This is the most commonly missed step.** Streamdown uses Tailwind for styling and the dist files must be scanned.2627**Tailwind v4** — add to `globals.css`:28```css29@source "../node_modules/streamdown/dist/*.js";30```3132**Tailwind v3** — add to `tailwind.config.js`:33```js34module.exports = {35 content: [36 "./app/**/*.{js,ts,jsx,tsx,mdx}",37 "./node_modules/streamdown/dist/*.js",38 ],39};40```4142### 3. Basic Usage4344```tsx45import { Streamdown } from 'streamdown';4647<Streamdown>{markdown}</Streamdown>48```4950### 4. With AI Streaming (Vercel AI SDK)5152```tsx53'use client';54import { useChat } from '@ai-sdk/react';55import { Streamdown } from 'streamdown';56import { code } from '@streamdown/code';5758export default function Chat() {59 const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();6061 return (62 <>63 {messages.map((msg, i) => (64 <Streamdown65 key={msg.id}66 plugins={{ code }}67 caret="block"68 isAnimating={isLoading && i === messages.length - 1 && msg.role === 'assistant'}69 >70 {msg.content}71 </Streamdown>72 ))}73 <form onSubmit={handleSubmit}>74 <input value={input} onChange={handleInputChange} disabled={isLoading} />75 </form>76 </>77 );78}79```8081### 5. Static Mode (Blogs, Docs)8283```tsx84<Streamdown mode="static" plugins={{ code }}>85 {content}86</Streamdown>87```8889## Key Props9091| Prop | Type | Default | Purpose |92|------|------|---------|---------|93| `children` | `string` | — | Markdown content |94| `mode` | `"streaming" \| "static"` | `"streaming"` | Rendering mode |95| `plugins` | `{ code?, mermaid?, math?, cjk? }` | — | Feature plugins |96| `isAnimating` | `boolean` | `false` | Streaming indicator |97| `caret` | `"block" \| "circle"` | — | Cursor style |98| `components` | `Components` | — | Custom element overrides |99| `controls` | `boolean \| object` | `true` | Interactive buttons |100| `linkSafety` | `LinkSafetyConfig` | `{ enabled: true }` | Link confirmation modal |101| `shikiTheme` | `[light, dark]` | `['github-light', 'github-dark']` | Code themes |102| `className` | `string` | — | Container class |103| `allowedElements` | `string[]` | all | Tag names to allow |104| `disallowedElements` | `string[]` | `[]` | Tag names to disallow |105| `allowElement` | `AllowElement` | — | Custom element filter |106| `unwrapDisallowed` | `boolean` | `false` | Keep children of disallowed elements |107| `skipHtml` | `boolean` | `false` | Ignore raw HTML |108| `urlTransform` | `UrlTransform` | `defaultUrlTransform` | Transform/sanitize URLs |109110For full API reference, see [references/api.md](references/api.md).111112## Plugin Quick Reference113114| Plugin | Package | Purpose |115|--------|---------|---------|116| Code | `@streamdown/code` | Syntax highlighting (Shiki, 200+ languages) |117| Mermaid | `@streamdown/mermaid` | Diagrams (flowcharts, sequence, etc.) |118| Math | `@streamdown/math` | LaTeX via KaTeX (requires CSS import) |119| CJK | `@streamdown/cjk` | Chinese/Japanese/Korean text support |120121**Math requires CSS:**122```tsx123import 'katex/dist/katex.min.css';124```125126For plugin configuration details, see [references/plugins.md](references/plugins.md).127128## References129130Use these for deeper implementation details:131132- **[references/api.md](references/api.md)** — Complete props, types, and interfaces133- **[references/plugins.md](references/plugins.md)** — Plugin setup, configuration, and customization134- **[references/styling.md](references/styling.md)** — CSS variables, data attributes, custom components, theme examples135- **[references/security.md](references/security.md)** — Hardening, link safety, custom HTML tags, production config136- **[references/features.md](references/features.md)** — Carets, remend, static mode, controls, GFM, memoization, troubleshooting137138## Example Configurations139140Copy and adapt from `assets/examples/`:141142- **[basic-streaming.tsx](assets/examples/basic-streaming.tsx)** — Minimal AI chat with Vercel AI SDK143- **[with-caret.tsx](assets/examples/with-caret.tsx)** — Streaming with block caret cursor144- **[full-featured.tsx](assets/examples/full-featured.tsx)** — All plugins, carets, link safety, controls145- **[static-mode.tsx](assets/examples/static-mode.tsx)** — Blog/docs rendering146- **[custom-security.tsx](assets/examples/custom-security.tsx)** — Strict security for AI content147148## Common Gotchas1491501. **Tailwind styles missing** — Add `@source` directive or `content` entry for `node_modules/streamdown/dist/*.js`1512. **Math not rendering** — Import `katex/dist/katex.min.css`1523. **Caret not showing** — Both `caret` prop AND `isAnimating={true}` are required1534. **Copy buttons during streaming** — Disabled automatically when `isAnimating={true}`1545. **Link safety modal appearing** — Enabled by default; disable with `linkSafety={{ enabled: false }}`1556. **Shiki warning in Next.js** — Install `shiki` explicitly, add to `transpilePackages`1567. **`allowedTags` not working** — Only works with default rehype plugins1578. **Math uses `$$` not `$`** — Single dollar is disabled by default to avoid currency conflicts