you can simply insert all off your html code in App.js file, reactjs doesn't require any .html file. just follow below code, hope you can understand it. i simply put all HTML code into parent div of App.js.

import React from 'react';

var perf =require('./App.html');

class App extends React.Component {
   render(){
      return (
        <div>
            <div class="carousel">
                <div class="carousel-item">
                    <img src={require("./1.png")} class="responsive-img"></img>
                </div>
                <div class="carousel-item">
                    <img src={require("./2.png")} class="responsive-img"></img>
                </div>
                <div class="carousel-item">
                    <img src={require("./3.png")} class="responsive-img"></img>
                </div>  
             </div>
        </div>      
      );
      }
      }
    export default App;
Answer from Fazal on Stack Overflow
Top answer
1 of 3
3

you can simply insert all off your html code in App.js file, reactjs doesn't require any .html file. just follow below code, hope you can understand it. i simply put all HTML code into parent div of App.js.

import React from 'react';

var perf =require('./App.html');

class App extends React.Component {
   render(){
      return (
        <div>
            <div class="carousel">
                <div class="carousel-item">
                    <img src={require("./1.png")} class="responsive-img"></img>
                </div>
                <div class="carousel-item">
                    <img src={require("./2.png")} class="responsive-img"></img>
                </div>
                <div class="carousel-item">
                    <img src={require("./3.png")} class="responsive-img"></img>
                </div>  
             </div>
        </div>      
      );
      }
      }
    export default App;
2 of 3
2

Just use react-create-app template and the basic html (head, meta) things are already in place, Just modify the src dir to meet you needs.

for example the index.js would be something like this,

import React from 'react';
import './App.css'; // For Your CSS file

class App extends React.Component {
   render(){
      return (
        <div class="carousel">
    <div class="carousel-item">
        <img src={require("./1.png")} class="responsive-img"></img>
    </div>
    <div class="carousel-item">
        <img src={require("./2.png")} class="responsive-img"></img>
    </div>
    <div class="carousel-item">
        <img src={require("./3.png")} class="responsive-img"></img>
    </div>
      );
   }
}
export default App;

if your need to change the base html you can do so in the public dir.

EDIT: (For the dependencies)

As you use materialize-css, You can use that by installing materialize-css@next as a dependency using npm with this cmd npm install materialize-css@next

More info about installing can be found here

Source: https://materializecss.com/getting-started.html

Top answer
1 of 3
3

you can simply insert all off your html code in App.js file, reactjs doesn't require any .html file. just follow below code, hope you can understand it. i simply put all HTML code into parent div of App.js.

import React from 'react';

var perf =require('./App.html');

class App extends React.Component {
   render(){
      return (
        <div>
            <div class="carousel">
                <div class="carousel-item">
                    <img src={require("./1.png")} class="responsive-img"></img>
                </div>
                <div class="carousel-item">
                    <img src={require("./2.png")} class="responsive-img"></img>
                </div>
                <div class="carousel-item">
                    <img src={require("./3.png")} class="responsive-img"></img>
                </div>  
             </div>
        </div>      
      );
      }
      }
    export default App;
2 of 3
2

Just use react-create-app template and the basic html (head, meta) things are already in place, Just modify the src dir to meet you needs.

for example the index.js would be something like this,

import React from 'react';
import './App.css'; // For Your CSS file

class App extends React.Component {
   render(){
      return (
        <div class="carousel">
    <div class="carousel-item">
        <img src={require("./1.png")} class="responsive-img"></img>
    </div>
    <div class="carousel-item">
        <img src={require("./2.png")} class="responsive-img"></img>
    </div>
    <div class="carousel-item">
        <img src={require("./3.png")} class="responsive-img"></img>
    </div>
      );
   }
}
export default App;

if your need to change the base html you can do so in the public dir.

EDIT: (For the dependencies)

As you use materialize-css, You can use that by installing materialize-css@next as a dependency using npm with this cmd npm install materialize-css@next

More info about installing can be found here

Source: https://materializecss.com/getting-started.html

Discussions

Insert HTML with React Variable Statements (JSX) [duplicate]
I am building something with React where I need to insert HTML with React Variables in JSX. Is there a way to have a variable like so: var thisIsMyCopy = ' copy copy copy str... More on stackoverflow.com
๐ŸŒ stackoverflow.com
reactjs - How to embed React Components in html pages - Stack Overflow
Simply adding React components into HTML code is not possible, because is not HTML at all, it is JSX. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to embed HTML in react components?
"best" is not to do it :D If you need to add plain html, use https://reactjs.org/docs/dom-elements.html -> dangerouslySetInnerHTML More on reddit.com
๐ŸŒ r/reactjs
6
2
May 22, 2021
Using React with plain HTML
The tutorial I was following Add React in One Minute Add React in One Minute This page demonstrates using React with no build tooling. React is loaded as a script tag. More on forum.freecodecamp.org
๐ŸŒ forum.freecodecamp.org
0
0
September 25, 2018
Top answer
1 of 2
4

If you're starting out, I recommend you bootstrap your apps using npx create-react-app. It'll give you a good sense of what a React app could look like, and some pointers for file structure.

Most React apps have an index.html file, which you can use like any normal HTML file. But, for the majority of your app, it's recommended to write your content in JSX (otherwise, you aren't getting the benefits of using React in the first place).

JSX

JSX looks very similar to regular HTML, with a handful of key differences:

  • Tag attributes tend to be in lowerCamelCase (onChange rather than onchange)
  • Instead of class (which is a reserved keyword in JavaScript), you need to use className

An Example Component

I've borrowed this sample code from React's official tutorial, which you should definitely check out if you haven't already.

This is a class Component, and your JSX goes inside of the render method:

import React from 'react';

class ShoppingList extends React.Component {
  render() {
    return (
      <div className="shopping-list">
        <h1>Shopping List for {this.props.name}</h1>
        <ul>
          <li>Instagram</li>
          <li>WhatsApp</li>
          <li>Oculus</li>
        </ul>
      </div>
    );
  }
}

What goes in index.html?

The only essential part of index.html is a <div id="root"></div>, which React will use to append the rest of the JSX.

This is also the place to add the usual metadata and icons.

As an example, here's the index.html file that comes with create-react-app. For most of my projects, I leave this pretty-much as-is:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>
2 of 2
2

In any given React component, there can only be one parent/top layer html element. You can get around this by using <React.Fragment> ...the rest of your html ... </React.Fragment> (or <>...</> depending on your version) or simply add a wrapping <div> around everything. JSX doesn't distinguish between "normal" html and "React" html, it just turns the React stuff into normal html (over simplification, but close enough for this question). Try it again and let me know if you encounter any problems.

const reactElement = (
  <div>
    React stuff
  </div>
);  

ReactDOM.render(
  reactElement,
  document.getElementById('root')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<div>
  <div id="root">
  </div>
  <div>
    just normal html
  </div>
</div>

๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_jsx.asp
React JSX
The expression can be a React variable, or property, or any other valid JavaScript expression. JSX will execute the expression and return the result: ... The HTML code must be wrapped in ONE top level element.
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_render.asp
React Render HTML
W3Schools has its own "Show React" tool where we will show the result of the code we explain in the tutorial. ... import { createRoot } from 'react-dom/client' createRoot(document.getElementById('root')).render( <p>Welcome!</p> ) Run Example ยป ยท The HTML code in this tutorial uses JSX which allows you to write HTML tags inside the JavaScript code:
๐ŸŒ
SheCodes
shecodes.io โ€บ athena โ€บ 7844-converting-html-to-react-guide-examples
[React] - Converting HTML to React - Guide & Examples - | SheCodes
Find out how to convert HTML code to React components. We provide guide and example with basic steps and React syntax to create working react component.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-use-reactjs-with-html-template
How to use ReactJS with HTML Template ? | GeeksforGeeks
April 28, 2025 - First, we need to create an HTML template to use in React JS. If you don't have an HTML template then simply download it. ... Add a blank Fragment tag and paste the body part of the HTML template in it. Follow the below code.
Find elsewhere
๐ŸŒ
Pluralsight
pluralsight.com โ€บ tech insights & how-to guides โ€บ tech guides & tutorials
How to Use Static HTML with React | Pluralsight
July 3, 2020 - By default, React does not permit you to inject HTML in a component, for various reasons including cross-site scripting. However, for some cases like a CMS or WYSIWYG editor, you have to deal with raw HTML.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to convert HTML template to React JS | React JS Tutorial | HTML to React JS - YouTube
How to convert HTML template to React JS | React JS Tutorial | HTML to React JS ๐Ÿ“ซ Business - manojdeshwal.dev@gmail.com ๐Ÿ“ฑ WhatsApp - +91 96257 01241?...
Published ย  August 12, 2022
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>
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-use-static-html-with-react
How to use static HTML with React
It is brought to the user's screen precisely as it is originally written or stored. We know that everything we render in React is in the form of components. Therefore, we can not directly add HTML in a React file.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How To Add React to HTML Website for beginners - YouTube
In this video I will show you how to add React to a basic HTML website and create two components.React Documentation: https://reactjs.org/docs/getting-starte...
Published ย  May 1, 2020
๐ŸŒ
Altcademy
altcademy.com โ€บ blog โ€บ how-to-include-html-file-in-reactjs-anchor-a-tag
How to include html file in ReactJS anchor a tag
November 12, 2023 - In conclusion, including an HTML file in a ReactJS anchor tag can be a bit tricky, but it's definitely possible. The trick is to convert the HTML file into a string and then use the dangerouslySetInnerHTML prop to insert that string into your JSX.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ javascript
Using React with plain HTML - JavaScript
September 25, 2018 - The tutorial I was following https://gist.github.com/gaearon/faa67b76a6c47adbab04f739cba7ceda https://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project <!DOCTYPE html> <html> <head> <meta charsetโ€ฆ
๐ŸŒ
Medium
medium.com โ€บ @to_pe โ€บ how-to-add-react-to-a-simple-html-file-a11511c0235f
How to add React to a simple html file | by Toni Petrina | Medium
January 16, 2017 - Then three libraries are referenced: react, react-dom, and babel-standalone. First two you need to render React into a DOM and the third one enables JSX and ES6. Then we get to write our code in a classical <script> block but with a twist: declare it as text/babel to enable transpilation from ES6 to ES5
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ html-to-react
html-to-react - npm
October 4, 2023 - We want to process the above HTML ... processing instructions: const React = require('react'); const HtmlToReact = require('html-to-react'); const HtmlToReactParser = require('html-to-react').Parser; const htmlToReactParser ...
      ยป npm install html-to-react
    
Published ย  Oct 04, 2023
Version ย  1.7.0
๐ŸŒ
Js
ru.react.js.org โ€บ docs โ€บ add-react-to-a-website.html
Add React to a Website โ€“ React
... First, open the HTML page you want to edit. Add an empty <div> tag to mark the spot where you want to display something with React. For example: <!-- ... existing HTML ... --> <div id="like_button_container"></div> <!-- ... existing HTML ...