Skip to main content

renderToStaticMarkup

renderToStaticMarkup renders a React tree to static HTML without React-specific attributes. This is useful for generating static pages or email templates where client-side hydration is not needed.
Unlike renderToString, this produces clean HTML without data-reactroot or other React attributes. The resulting HTML cannot be hydrated on the client.

Reference

renderToStaticMarkup(element, options?)

Renders a React element to a static HTML string without React attributes.

Parameters

  • element: ReactNode - The React element to render
  • options: Object (optional)
    • identifierPrefix: string - Prefix for IDs generated by useId

Returns

Returns a string containing clean HTML without React-specific attributes.

Caveats

  • No hydration: Output cannot be hydrated with hydrateRoot on the client
  • No Suspense: Does not support Suspense boundaries
  • Blocking: Synchronous rendering blocks until complete
  • No interactivity: Event handlers and client-side state won’t work

Usage

Static site generation

Use renderToStaticMarkup to generate static HTML files at build time:

Email templates

Generate HTML emails using React components:

Documentation generation

Generate static documentation pages:

RSS feed generation

Generate RSS XML using React components:

Differences from renderToString

Output comparison

When to use each

renderToStaticMarkup

Use when:
  • Generating static sites
  • Creating email templates
  • No client-side interactivity needed
  • Cleaner HTML desired
  • Building time content

renderToString

Use when:
  • Server-side rendering with hydration
  • Client-side interactivity needed
  • React will run on the client
  • Event handlers required
  • Dynamic updates expected

Common Patterns

Building a static site generator

Template rendering utility

Performance Considerations

Memory usage

Like renderToString, renderToStaticMarkup buffers the entire output in memory:

Build performance

Runtime Availability

renderToStaticMarkup is available across all runtimes:

Common Issues

renderToStaticMarkup produces static HTML without React. Event handlers won’t be attached:
Solution: Use renderToString with client-side hydration if you need interactivity.
Attempting to hydrate markup from renderToStaticMarkup will fail:
Solution: Use renderToString on the server if you need client-side hydration.
Like renderToString, renderToStaticMarkup doesn’t support Suspense:
Solution: Ensure all data is loaded before rendering, or use streaming APIs.

See Also