How to use innerHtml in React JS ? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share 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 Like