"best" is not to do it :D If you need to add plain html, use https://reactjs.org/docs/dom-elements.html -> dangerouslySetInnerHTML Answer from Noch_ein_Kamel on reddit.com
Discussions

reactjs - How to embed React Components in html pages - Stack Overflow
But it is not possible to add JSX into HTML, like: React is Javascript, so everything that is necessary to add Javascript functionality to HTML also applies to adding React to HTML. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to embed text/html in react component?
I'm trying to embedding text/html in a react Modal component. But when I run my app with electron the Google Inspector show me some errors. Uncaught invariant.js:38 Uncaught Invariant Violation: ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Embed React JS Within an Existing Page
For the purposes of learning React, and for migrating existing applications to React, I would like to embed a React component within an existing page that is already full of HTML and JS of its own - More on stackoverflow.com
๐ŸŒ stackoverflow.com
reactjs - Embedding full react application into an existing web page - Stack Overflow
I'm looking to embed my react application into an existing plain html / javascript website. What I've found so far is that you are only able to embed individual components into existing websites, not More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_render.asp
React Render HTML
The root node is the HTML element where you want to display the result. It is like a container for content, managed by React.
๐ŸŒ
Pluralsight
pluralsight.com โ€บ what makes pluralsight different | pluralsight โ€บ tech guides & tutorials
How to Use Static HTML with React | Pluralsight
July 3, 2020 - If you try to render an HTML string inside a component directly, React will automatically sanitize it and render it as a plain string. const myHTML = `<h1>John Doe</h1>`; const App = () => <div>{myHTML}</div>; The above code will not render the string "John Doe" in a heading. Instead, the complete string, including the H1 tags, will be displayed to the user, thanks to React.
๐ŸŒ
Martin Adams
meda.io โ€บ embed-react-into-an-html-web-page
Embed React into an HTML web page - Martin Adams
May 1, 2024 - It's actually an API query language</div>; } return <div className="quiz"> <p>What is GraphQL?</p> {question} {answer} </div>; } } ReactDOM.render( <Quiz />, document.getElementById('quiz') ); </script> </head> <body> <div id="quiz"></div> </body> </html> There you have it, a very quick way to embed React onto a web page.
๐ŸŒ
DEV Community
dev.to โ€บ bytebodger โ€บ embedding-data-into-reactjsx-elements-3jcp
Embedding Data Into React/JSX Elements - DEV Community
March 23, 2023 - HTML affords us a lot of freedom to "stuff" data where it's needed. For example, you could use the longdesc attribute to embed the paintIndex right into the HTML element itself.
๐ŸŒ
DhiWise
dhiwise.com โ€บ post โ€บ react-inject-html-a-comprehensive-guide
The Ultimate Guide to React HTML Injection
September 5, 2024 - When working with React, developers ... HTML string injection comes into play. React components return HTML content using a syntax called JSX, which resembles HTML tags within JavaScript....
Find elsewhere
๐ŸŒ
Bacancy Technology
bacancytechnology.com โ€บ qanda โ€บ react โ€บ embed-react-components-in-html-pages
Step-by-Step Guide to Embed React Components in HTML Pages
August 14, 2025 - This guide explains how to embed React components in regular HTML pages using a simple and effective approach.
๐ŸŒ
EmbedSocial
embedsocial.com โ€บ all collections โ€บ embedreviews โ€บ display reviews โ€บ applications โ€บ how to embed code in a react application
How to Embed Code in a React Application | EmbedSocial Help Center
(function(d, s, id) { var js; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "https://embedsocial.com/cdn/ht.js"; d.getElementsByTagName("head")[0].appendChild(js); }(document, "script", "EmbedSocialHashtagScript")); 3. Next head over to your React application and create a new component in your components directory and paste the HTML code inside the render function:
๐ŸŒ
Embedsocial
help.embedsocial.com โ€บ en โ€บ articles โ€บ 4797000-how-to-embed-code-in-a-react-application
How to Embed Code in a React Application | EmbedSocial Help Center
(function(d, s, id) { var js; if ... head over to your React application and create a new component in your components directory and paste the HTML code inside the render function:...
Top answer
1 of 6
5

Simply adding React components into HTML code is not possible, because <MyComponent></MyComponent> is not HTML at all, it is JSX.

Explaination

JSX is a special syntax that can be 'transpiled' to Javascript, so in essence <MyComponent></MyComponent> will end up beeing Javascript code, which obviously can not just be put into HTML code.

The Javascript code generated from JSX then will be executed and generates actual HTML code.

It is possible to add HTML tags into JSX, because HTML can be interpreted as JSX (and will be transpiled to Javascript as well), like:

class MyComponent extends React.Component {
    render(){
        return <div>
            <h2>HTML in JSX works</h2>
            <SomeOtherJsxComponent />
        </div>;
    }
}

But it is not possible to add JSX into HTML, like:

<body>
    <div>
        <JsxInHtmlDoesNotWork />
    </div>
</body>

React is Javascript, so everything that is necessary to add Javascript functionality to HTML also applies to adding React to HTML.

(nearest) Solution

So what you could do is to move your existing HTML into to some JSX wrapper (which is probably not what you would like to do, because this goes in the direction of creating a SPA, what you don't want), e.g.:

<html><head>
    <title>My web site</title>
</head><body>

<h1>Some HTML title</h1>
<p>Some HTML content.</p>

<!-- add a container, where you want to include react components -->
<div id="injected-react-content"></div>

<!-- import the react libraray -->
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

<!-- setup react root component other components -->
<script type="text/babel">
    class RootComponent extends React.Component {
        render(){
            return <div>
                <MyComponent />
            </div>;
        }
    }

    class MyComponent extends React.Component {
        render(){
            return (<div>This is a simple component</div>);
        }
    }

    const domContainer = document.querySelector('#injected-react-content');
    ReactDOM.render( React.createElement(RootComponent), domContainer );
</script>

</body></html>

For some more background information on how to add React to an existing HTML website, see e.g.:

  • stackoverflow.com/questions/65917670/how-to-use-react-components-as-part-of-legacy-html-js-app
  • stackoverflow.com/questions/69607103/react-component-not-displayed-in-html
2 of 6
4

Use

ReactDOM.render(<MyComponent />, document.getElementById('id'));

You can render in your HTML like this:

<div id="id"></div>
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ embed-your-react-application-basic-html-pages-muhammad-salif
Embed your react application in basic HTML pages
April 2, 2021 - Create a basic server using node-js & express that will serve build files of react app to client-side. Create an HTML file and embed react application in it.
๐ŸŒ
React
react.dev โ€บ learn โ€บ add-react-to-an-existing-project
Add React to an Existing Project โ€“ React
Many React-based frameworks are full-stack and let your React app take advantage of the server. However, you can use the same approach even if you canโ€™t or donโ€™t want to run JavaScript on the server. In that case, serve the HTML/CSS/JS export (next export output for Next.js, default for Gatsby) at /some-app/ instead.
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ how-to-embed-a-react-application-on-any-website-1bee1d15617f
How to Embed a React Application in Any Website | by Jeremiah Tabb | Better Programming
May 20, 2020 - 4. Lastly, we can call our new static assets as JS files and point our React widget to mount a <div></div> on our website! Here is my example HTML page that has two React applications mounted as React widgets:
๐ŸŒ
Selleo
selleo.com โ€บ home โ€บ blog โ€บ how-to-create-embedded-react-widget
How to Create Embedded React Widget - Selleo
January 14, 2026 - Finally, update the code to use the library of HTML-to-react and seamlessly convert HTML markups to produce react components in case the component was a container. Overall, there are multiple ways to create an embedded React widget in a page, site or an application.
Top answer
1 of 2
5

ReactJs and almost every frontend library developed in a way so that one can run multiple apps of same or different library/framework. Now let's understand How you can use ReactJs to control part of your DOM or can say a part of a view/page. First step is to load ReactJs and react DOM in your html via a cdn link. Now it's time to render a component which you had already developed. For your ease, I have created a stackblitz javascript project for your reference. Here is the link https://stackblitz.com/edit/js-gmhwuw?file=index.js,index.html,hello-world.js

But I'm explaining the same here as well. React and ReactDOM will register itself to window object so that you can use both object once script is loaded. We need to understand here about React is that React never take control of whole DOM. It will always control a container and we actually register a container div with React where React will render provided component. So we can say here that a page can have multiple ReactJs applications. Here is code which can use to render a React component inside a div with id react-app

// import your component via lazy loading
import('./hello-world.js').then((comp) => {
  // get the container where you want to render
  const reactDiv = document.getElementById('react-app');
  const reactRoot = ReactDOM.createRoot(reactDiv);
  reactRoot.render(comp.default());

  // here I'm registering one more react application in another container
  const reactDiv2 = document.getElementById('react-app2');
  const reactRoot2 = ReactDOM.createRoot(reactDiv2);
  reactRoot2.render(comp.default());
});

Hope I'm able to resolve your query but please comment if you need any further help

2 of 2
1

You can implement single-spa. With it, you can then create micro-frontends in ReactJS that get embedded where needed.

Top answer
1 of 2
27

I was able to embed my full react application by doing the following...

  1. I built my react app production files with npm run build
  2. I copied those files into the existing web project at the root level
  3. Then I opened the index.html file generated from npm run build and copied the scripts in the head and body sections to the page I wanted to drop in my application
  4. Finally I added a div with the id root (this is what my renderDOM method is looking for) where I wanted my application to appear on the existing web page.

That was it. Super easy, thanks for the help!

2 of 2
2

Just wanted to add a quick additional approach here.

If you already have a Flask app and you're trying to put React components or an app (so the base component of an app) onto an existing HTML page in the Flask app, basically the only thing that you need is Babel, unless you are able to write React components without using JSX (so in plain Javascript) in which case you'd need nothing.

Step 1: To attach Babel to your project, you'll have to grab the Babel node modules which means your project will be associated with NPM for the sole purpose of using the Babel functions. You can do this by running the following commands in your project root directory (Node.js must be installed):

npm init -y

npm install babel-cli@6 babel-preset-react-app@3

Step 2: Once Babel is attached to your project, you'll have to actually transpile the existing React component .js files from JSX into plain Javascript like so:

npx babel --watch (jsdirectory) --out-dir (outputdirectory) --presets react-app/prod

where (jsdirectory) is the path to the directory where your React component files written using JSX are, and (outputdirectory) is where you want your translated files to show up--use . for (outputdirectory) to have transpiled files appear in your root directory.

Step 3: After the plain Javascript versions of your React files appear, make sure they are linked to your HTML page instead of the original JSX-utilizing files (replace the original script tag's .js file)

Step 4: Make sure the HTML page in question is linked to the .CSS files you want (they will modify the transpiled Javascript in the same manner as they did the JSX files in a project made using Create-React-App because the class names are the same) as well as the required React resources:

<script src="https://unpkg.com/react@16/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js" crossorigin></script>

After you do those quick steps your React components should render no problem on that page in your Python-Flask application.

๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-use-static-html-with-react
How to use static HTML with React
Try changing the style and content of the htmlString and see how dangerouslySetInnerHTML modifies the DOM to display the passed string. A better way to take care of security concerns is to use a library like DOMPurify. DOMPurify can be modified to sanitize just those tags that we authorize, for instance, the h2 and p tag. Since this is an external library, we will need to install it first using: ... import React from 'react'; import DOMPurify from 'dompurify'; function StaticHTML() { const htmlString = ` <h2>We are using a header tag in DOMPurify</h2> <p>We are using a paragraph tag in DOMPuri