content: [API Reference](https://react.dev/reference/react)
  
  [Server APIs](https://react.dev/reference/react-dom/server)
  
  # renderToString[Link for this heading]()
  
  ### Pitfall
  
  `renderToString` does not support streaming or waiting for data. [See the alternatives.]()
  
  `renderToString` renders a React tree to an HTML string.
  
  ```
  
  const html = renderToString(reactNode, options?)
  ```
  
  - [Reference]()
    
    - [`renderToString(reactNode, options?)`]()
  - [Usage]()
    
    - [Rendering a React tree as HTML to a string]()
  - [Alternatives]()
    
    - [Migrating from `renderToString` to a streaming render on the server]()
    - [Migrating from `renderToString` to a static prerender on the server]()
    - [Removing `renderToString` from the client code]()
  - [Troubleshooting]()
    
    - [When a component suspends, the HTML always contains a fallback]()
  
  * * *
  
  ## Reference[Link for Reference]()
  
  ### `renderToString(reactNode, options?)`[Link for this heading]()
  
  On the server, call `renderToString` to render your app to HTML.
  
  ```
  
  import { renderToString } from 'react-dom/server';
  
  
  
  const html = renderToString(<App />);
  ```
  
  On the client, call [`hydrateRoot`](https://react.dev/reference/react-dom/client/hydrateRoot) to make the server-generated HTML interactive.
  
  [See more examples below.]()
  
  #### Parameters[Link for Parameters]()
  
  - `reactNode`: A React node you want to render to HTML. For example, a JSX node like `<App />`.
  - **optional** `options`: An object for server render.
    
    - **optional** `identifierPrefix`: A string prefix React uses for IDs generated by [`useId`.](https://react.dev/reference/react/useId) Useful to avoid conflicts when using multiple roots on the same page. Must be the same prefix as passed to [`hydrateRoot`.](https://react.dev/reference/react-dom/client/hydrateRoot)
  
  #### Returns[Link for Returns]()
  
  An HTML string.
  
  #### Caveats[Link for Caveats]()
  
  - `renderToString` has limited Suspense support. If a component suspends, `renderToString` immediately sends its fallback as HTML.
  - `renderToString` works in the browser, but using it in the client code is [not recommended.]()
  
  * * *
  
  ## Usage[Link for Usage]()
  
  ### Rendering a React tree as HTML to a string[Link for Rendering a React tree as HTML to a string]()
  
  Call `renderToString` to render your app to an HTML string which you can send with your server response:
  
  ```
  
  import { renderToString } from 'react-dom/server';
  
  
  
  // The route handler syntax depends on your backend framework
  
  app.use('/', (request, response) => {
  
    const html = renderToString(<App />);
  
    response.send(html);
  
  });
  ```
  
  This will produce the initial non-interactive HTML output of your React components. On the client, you will need to call [`hydrateRoot`](https://react.dev/reference/react-dom/client/hydrateRoot) to *hydrate* that server-generated HTML and make it interactive.
  
  ### Pitfall
  
  `renderToString` does not support streaming or waiting for data. [See the alternatives.]()
  
  * * *
  
  ## Alternatives[Link for Alternatives]()
  
  ### Migrating from `renderToString` to a streaming render on the server[Link for this heading]()
  
  `renderToString` returns a string immediately, so it does not support streaming content as it loads.
  
  When possible, we recommend using these fully-featured alternatives:
  
  - If you use Node.js, use [`renderToPipeableStream`.](https://react.dev/reference/react-dom/server/renderToPipeableStream)
  - If you use Deno or a modern edge runtime with [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API), use [`renderToReadableStream`.](https://react.dev/reference/react-dom/server/renderToReadableStream)
  
  You can continue using `renderToString` if your server environment does not support streams.
  
  * * *
  
  ### Migrating from `renderToString` to a static prerender on the server[Link for this heading]()
  
  `renderToString` returns a string immediately, so it does not support waiting for data to load for static HTML generation.
  
  We recommend using these fully-featured alternatives:
  
  - If you use Node.js, use [`prerenderToNodeStream`.](https://react.dev/reference/react-dom/static/prerenderToNodeStream)
  - If you use Deno or a modern edge runtime with [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API), use [`prerender`.](https://react.dev/reference/react-dom/static/prerender)
  
  You can continue using `renderToString` if your static site generation environment does not support streams.
  
  * * *
  
  ### Removing `renderToString` from the client code[Link for this heading]()
  
  Sometimes, `renderToString` is used on the client to convert some component to HTML.
  
  ```
  
  // 🚩 Unnecessary: using renderToString on the client
  
  import { renderToString } from 'react-dom/server';
  
  
  
  const html = renderToString(<MyIcon />);
  
  console.log(html); // For example, "<svg>...</svg>"
  ```
  
  Importing `react-dom/server` **on the client** unnecessarily increases your bundle size and should be avoided. If you need to render some component to HTML in the browser, use [`createRoot`](https://react.dev/reference/react-dom/client/createRoot) and read HTML from the DOM:
  
  ```
  
  import { createRoot } from 'react-dom/client';
  
  import { flushSync } from 'react-dom';
  
  
  
  const div = document.createElement('div');
  
  const root = createRoot(div);
  
  flushSync(() => {
  
    root.render(<MyIcon />);
  
  });
  
  console.log(div.innerHTML); // For example, "<svg>...</svg>"
  ```
  
  The [`flushSync`](https://react.dev/reference/react-dom/flushSync) call is necessary so that the DOM is updated before reading its [`innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) property.
  
  * * *
  
  ## Troubleshooting[Link for Troubleshooting]()
  
  ### When a component suspends, the HTML always contains a fallback[Link for When a component suspends, the HTML always contains a fallback]()
  
  `renderToString` does not fully support Suspense.
  
  If some component suspends (for example, because it’s defined with [`lazy`](https://react.dev/reference/react/lazy) or fetches data), `renderToString` will not wait for its content to resolve. Instead, `renderToString` will find the closest [`<Suspense>`](https://react.dev/reference/react/Suspense) boundary above it and render its `fallback` prop in the HTML. The content will not appear until the client code loads.
  
  To solve this, use one of the [recommended streaming solutions.]() For server side rendering, they can stream content in chunks as it resolves on the server so that the user sees the page being progressively filled in before the client code loads. For static site generation, they can wait for all the content to resolve before generating the static HTML.
  
  [PreviousrenderToStaticMarkup](https://react.dev/reference/react-dom/server/renderToStaticMarkup)
  
  [NextStatic APIs](https://react.dev/reference/react-dom/static)