How to use innerHtml in React JS ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report React.js provides a easy way of handling UI updates. However, sometimes you need to inject HTML directly into your components. PrerequisitesIntroduction to ReactReact ComponentsReact HooksNPM or NPXIn this article, we are going to learn how can we use InnerHTML in React JS. We can add HTML into ReactJS by using the 'dangerouslySetInnerHTML' property. As the name suggests it is dangerous because it directly injects HTML into your react components, which can lead to security issues and other manipulative problems. It can also increase risks like cross-site scripting (XSS). Steps to Create the React ApplicationStep 1: Create a React application using the following command. npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command. cd foldernameProject Structure: Project structureExample: Here we are creating a component 'HTML' in which we are creating a const and storing a html element as a value and passing that value in a div element for dangerouslySetInnerHTML , So that we can inject that HTML in out Reactjs component and render it on screen. After that we are importing that 'HTML' component in App.js file and it will render to the screen. JavaScript //HTML.js import React from 'react'; function HTML() { const htmlContent = `<div> <h3> GeekForGeeks </h3> <p> innerHTML in reactjs </p> </div>`; return ( <div> <div dangerouslySetInnerHTML={ { __html: htmlContent } } /> </div> ); } export default HTML; JavaScript //App.js import './App.css'; import HTML from './HTML'; function App() { return ( <div className="center"> <HTML /> </div> ); } export default App; Steps to run the application: npm startOutput: Output Comment More infoAdvertise with us Next Article How to use innerHtml in React JS ? M meetahaloyx4 Follow Improve Article Tags : Web Technologies ReactJS React-Questions Similar Reads How to use innerHTML in JavaScript ? The innerHTML property in JavaScript allows you to get or set the HTML content of an element as a string. Syntax ForGetting HTML content of an element:let element = document.getElementById("myElementId"); let htmlContent = element.innerHTML;Setting HTML content of an element:let element = document.g 2 min read How to use Inline Styles in React ? ReactJS is a JavaScript library that is used to build a user interface. React makes it easy to create an interactive user interface by using a component-based approach. It offers various ways to apply styles to components. One of the methods is using inline styles, where styles are defined directly 3 min read How To Use Inline Styles in ReactJS? Inline styles in React allow you to directly apply CSS styles to elements using the style attribute. This is often used for dynamic styling, where styles need to be applied based on the component's state or props. Inline styles in React are written as JavaScript objects. Each CSS property is camelCa 3 min read How to add code input in React JS? In this article, we are going to learn how we can add Code Input in React JS. React is a front-end JavaScript library for constructing user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies. Approach to add code input: To incorporate our 2 min read How to use styles in ReactJS ? React is a popular JavaScript library for building single-page applications (SPAs) with dynamic user interfaces. Styling in React can be done in various ways, each with its advantages. In this article, we will explore different approaches to applying styles in React, including inline styles, CSS fil 4 min read How to Insert an Iframe in React ? In this article, we are going to insert an Iframe in React JS. The iframe stands for the inline frame. The "iframe" tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders. An inline frame is used to embed another do 1 min read How to use ReactJS with HTML Template ? We all know ReactJS is a front-end development framework. For the front end, we need to create HTML templates. So, this article teaches you how to use HTML templates in ReactJS. The process is very simple. Prerequisites:NodeJS or NPMReact JSApproach: We will create a simple one-page HTML template i 4 min read How to Render Lists in React? In React, rendering lists of data is a common task. There are multiple approaches to achieve this. In this article we will explore various approaches to render lists in React. Table of Content Using map() methodUsing forEach() methodSteps to Setup a React App:Step 1: Create a React application using 2 min read How to use events in ReactJS ? Modern webpages rely on user interactions, triggering events like clicks or keypresses. React facilitates event handling with built-in methods, allowing developers to create listeners for dynamic interfaces and responses. JavaScript events, inherent to the DOM, use bubbling propagation by default, m 2 min read How to align Text in React Material UI? The Typography component of Material UI is used to present your text and content as clearly and efficiently as possible. Import: import Typography from '@material-ui/core/Typography'; // OR import { Typography } from '@material-ui/core';Syntax: It sets the alignment property. <object align="value 3 min read Like