How to Set up React in a HTML File
Most React projects rely on complex build tools. But did you know you can set up simple React components directly within an HTML file? This approach is ideal for rapid prototyping or adding interactive elements to existing pages.
Step 1: Include the Libraries
Click here for the simplest cloud platform. Get started with a $200 credit.
Add the following CDN scripts inside the <head>
of your HTML file:
HTML
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
- Quick Explanation: (Provide a sentence or two about what each library does – React, ReactDOM, Babel.)
Step 2: Prepare Your HTML
Create a div
to hold your React app:
HTML
<body>
<div id="root"></div>
</body>
Step 3: Write React Code (with Babel)
Click here for expert-led courses for sharpening coding skills…free trial…
Embed this inside <script type="text/babel">
tags:
JavaScript
class App extends React.Component {
render() {
return (
<div>
<h1>React Setup</h1>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));
Step 4: Production Mode
- Important: Replace the development CDN links with production-ready versions.
Recent Posts
- Can n8n Replace LangGraph? Comparing Visual AI Workflows to Code-Based Agents
- Cloudflare’s Container Buzz Is Real—But Docker on DigitalOcean Is What You Should Be Switching To
- Cloudflare Containers vs Docker: The Battle for the Future of Deployment
- n8n vs. Langflow: Building Your First AI Agent with Low-Code Tools
- Top Laptops for Coding in 2025: The Ultimate Guide for Coders