renderToStaticMarkup
Renders a React tree to static HTML string without React-specific attributes likedata-reactroot.
Use
renderToStaticMarkup when you want to generate static HTML that won’t be hydrated by React on the client. This is ideal for email templates, static documentation, or non-interactive pages.Reference
renderToStaticMarkup(reactNode, options?)
Call renderToStaticMarkup to render your React tree to static HTML.
/src/server/ReactDOMLegacyServerNode.js:30-40
Parameters
ReactNode
required
A React node you want to render to HTML. For example, a JSX element like
<Page />.ServerOptions
Optional server rendering options.
Returns
string
A static HTML string without any React-specific attributes. Cannot be hydrated with
hydrateRoot on the client.Differences from renderToString
Output Comparison
Usage Examples
Email Template Generation
Static Site Generation
RSS Feed Generation
PDF Report Generation
SVG Generation
Use Cases
1. Email Marketing
Generate HTML emails with React components:2. Static Documentation
Generate documentation sites at build time:3. Open Graph Images
Generate social media preview images:TypeScript
Performance Benefits
Smaller Output
Faster Rendering
Limitations
No Hydration Support
No Suspense Support
Same asrenderToString, does not support Suspense boundaries:
Common Pitfalls
Don’t use for interactive content
Remember DOCTYPE for full HTML documents
Testing with renderToStaticMarkup
Best Practices
- Use for truly static content - No need for client-side interactivity
- Smaller HTML size - Perfect for emails and static pages
- Include DOCTYPE - For complete HTML documents
- Inline styles for emails - Email clients don’t support external CSS
- Escape user content - React handles this automatically
Related APIs
- renderToString - SSR with hydration support
- renderToPipeableStream - Streaming SSR
- createRoot - Client-side rendering