React is one of the most popular libraries for building interactive user interfaces. While most tutorials focus on creating full React applications with build tools like Webpack or Vite, there are situations where you might want to embed a React component into an existing HTML page without setting up a full project.
This guide explains how to embed React components in regular HTML pages using a simple and effective approach.
You cannot directly place a React component like: inside standard HTML. The reason is rooted in how React works under the hood.
For example: <MyComponent /> is transpiled to: React.createElement(MyComponent);
React then uses this JavaScript to generate and render real HTML on the page.
You can embed regular HTML within JSX:
function MyComponent() {
return (
<div>
<h2>HTML inside JSX works</h2>
<othercomponent>
</othercomponent></div>
);
}
However, you cannot embed JSX directly into raw HTML:
<code><body>
<div>
<JsxInHtmlDoesNotWork />
</div>
</body></code>
To embed React into an existing HTML page, you should:
<!DOCTYPE html>
<html>
<head>
<title>Embed React Example</title>
</head>
<body>
<h1>Existing Website Title</h1>
<p>This is some static HTML content.</p>
<div id="react-root"></div>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
class MyComponent extends React.Component {
render() {
return <div>This is a React component embedded in HTML.</div>;
}
}
const root = ReactDOM.createRoot(document.getElementById('react-root'));
root.render(<MyComponent />);
</script>
</body>
</html>
Code snippet compatible for React version 18:
<!DOCTYPE html>
<html>
<head>
<title>Embed React Example with Hooks</title>
</head>
<body>
<h1>Existing Website Title</h1>
<p>This is some static HTML content.</p>
<div id="react-root"></div>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
const { useState } = React;
function MyComponent() {
const [count, setCount] = useState(0);
return (
<div>
<p>This is a React component embedded in HTML.</p>
<p>Counter: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}
const rootElement = document.getElementById('react-root');
const root = ReactDOM.createRoot(rootElement);
root.render(<MyComponent />);
</script>
</body>
</html>
Embedding React into a static HTML page is a practical solution for adding interactive features to existing websites without committing to a full single-page application architecture. While it works well for small-scale use cases or legacy integration, modern development workflows should leverage proper build tools to maximize efficiency and maintainability.
Work with our skilled React developers to accelerate your project and boost its performance.
Copyright © 2026 Niotechone Software Solution Pvt. Ltd. All Rights Reserved.