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 renderoptions:Object(optional)identifierPrefix:string- Prefix for IDs generated byuseId
Returns
Returns astring containing clean HTML without React-specific attributes.
Caveats
Usage
Static site generation
UserenderToStaticMarkup to generate static HTML files at build time:
Email templates
Generate HTML emails using React components:Documentation generation
Generate static documentation pages:- Build Script
- Doc Component
RSS feed generation
Generate RSS XML using React components:Differences from renderToString
Output comparison
- renderToStaticMarkup
- renderToString
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
LikerenderToString, renderToStaticMarkup buffers the entire output in memory:
Build performance
Runtime Availability
renderToStaticMarkup is available across all runtimes:
- Node.js
- Edge Runtime
- Bun
Common Issues
Event handlers don't work
Event handlers don't work
renderToStaticMarkup produces static HTML without React. Event handlers won’t be attached:renderToString with client-side hydration if you need interactivity.Cannot hydrate static markup
Cannot hydrate static markup
Attempting to hydrate markup from Solution: Use
renderToStaticMarkup will fail:renderToString on the server if you need client-side hydration.Suspense not supported
Suspense not supported
Like Solution: Ensure all data is loaded before rendering, or use streaming APIs.
renderToString, renderToStaticMarkup doesn’t support Suspense:See Also
renderToString- Render with React attributes for hydration- Server Rendering Overview - Compare all server rendering approaches
- Static Site Generation Guide - Best practices for SSG with React