Skip to main content

renderToStaticMarkup

Renders a React tree to static HTML string without React-specific attributes like data-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

HTML generated by renderToStaticMarkup cannot be hydrated with hydrateRoot. If you need interactivity, use renderToString or renderToPipeableStream instead.

No Suspense Support

Same as renderToString, does not support Suspense boundaries:

Common Pitfalls

Don’t use for interactive content

Remember DOCTYPE for full HTML documents

Testing with renderToStaticMarkup

Best Practices

  1. Use for truly static content - No need for client-side interactivity
  2. Smaller HTML size - Perfect for emails and static pages
  3. Include DOCTYPE - For complete HTML documents
  4. Inline styles for emails - Email clients don’t support external CSS
  5. Escape user content - React handles this automatically