🌐
npm
npmjs.com › package › html-react-parser
html-react-parser - npm
1 month ago - html-dom-parser has been upgraded to v7 and domhandler has been upgraded to v6. Migrated to TypeScript. CommonJS imports require the .default key: const parse = require('html-react-parser').default;
      » npm install html-react-parser
    
Published   Apr 08, 2026
Version   6.0.1
🌐
GitHub
github.com › remarkablemark › html-react-parser
GitHub - remarkablemark/html-react-parser: 📝 HTML to React parser.
html-dom-parser has been upgraded to v7 and domhandler has been upgraded to v6. Migrated to TypeScript. CommonJS imports require the .default key: const parse = require('html-react-parser').default;
Starred by 2.4K users
Forked by 139 users
Languages   TypeScript 87.9% | JavaScript 12.1%
🌐
npm
npmjs.com › package › @types › react-html-parser
@types/react-html-parser - npm
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-html-parser. import { DomElement } from "htmlparser2"; import { ReactElement } from "react"; export interface Transform { // eslint-disable-next-line @typescript-eslint/no-invalid-void-type (node: DomElement, index: number, transform?: Transform): ReactElement | void | null; } export interface Options { decodeEntities?: boolean | undefined; transform?: Transform | undefined; preprocessNodes?(nodes: DomElement[]): any; } export function convertNodeToElement( node: DomElement, index: number, transform: Transform, ): ReactElement; export function processNodes(nodes: DomElement[], transform: Transform): ReactElement[]; export default function HtmlParser(html: string, options?: Options): ReactElement[];
      » npm install @types/react-html-parser
    
🌐
GitHub
gist.github.com › natterstefan › 3bc712eca6ff88781d687b7240a78cc1
html-react-parser | TypeScript solution · GitHub
html-react-parser | TypeScript solution. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › remarkablemark › html-react-parser › blob › master › examples › create-react-app-typescript › src › App.tsx
html-react-parser/examples/create-react-app-typescript/src/App.tsx at master · remarkablemark/html-react-parser
import parse, { domToReact, htmlToDOM, Element } from 'html-react-parser'; import './App.css'; · console.log(domToReact); console.log(htmlToDOM); · export default function App() { return ( <div className="App"> {parse( ` <h1 style="font-family: 'Lucida Grande';"> HTMLReactParser<br class="remove"> with Create React App (TypeScript) </h1> `, { replace(domNode) { if ( domNode instanceof Element && domNode.attribs.class === 'remove' ) { return <></>; } }, } )} </div> ); }
Author   remarkablemark
🌐
CodeSandbox
codesandbox.io › s › html-react-parser-typescript-0g0ct
html-react-parser-typescript - CodeSandbox
February 6, 2020 - html-react-parser-typescript by remarkablemark using html-react-parser, react, react-dom, react-scripts
Published   Feb 06, 2020
Author   remarkablemark
🌐
JSFiddle
jsfiddle.net › remarkablemark › 7v86d800
html-react-parser example - JSFiddle - Code Playground
Adding External Resources will no longer create a list of resources in the sidebar but will be injected as a LINK or SCRIPT tag inside of the HTML panel.
Top answer
1 of 7
57

You probably want to look deeper into dangerouslySetInnerHTML. Here is an example how to render HTML from a string in a React component:

import React from 'react';
import { render } from 'react-dom';

const htmlString = '<h1>Hello World! </h1>';

const App = () => (
  <div dangerouslySetInnerHTML={{ __html: htmlString }} />
);

render(<App />, document.getElementById('root'));

Full example here: https://codesandbox.io/s/xv40xXQzE

Read more about dangerouslySetInnerHTML in the React docs here: https://facebook.github.io/react/docs/dom-elements.html#dangerouslysetinnerhtml

2 of 7
30

As pointed out in this answer by EsterlingAccimeYoutuber, you can use a parser in case you don't want to use dangerouslySetInnerHTML attribute.

By now, react-html-parser has not been updated for 3 years, so I went looking for a different module.

html-react-parser does same job but is frequently maintained and updated.

It should be good practice to sanitize your html-String to prevent XSS attacks. dompurify can be used for that.

I updated EsterlingAccimeYoutuber's code-example to the following:

import React from 'react';
import { render } from 'react-dom';
import parse from 'html-react-parser';
import DOMPurify from 'dompurify';

const SpecialButton = ({ children, color }) => (
  <button style={{color}}>{children}</button>
);

const htmlFromCMS = `
<div>Hi, 
  <SpecialButton color="red">My Button</SpecialButton>
</div>`;

const htmlFrom = (htmlString) => {
        const cleanHtmlString = DOMPurify.sanitize(htmlString,
          { USE_PROFILES: { html: true } });
        const html = parse(cleanHtmlString);
        return html;
}

const App = () => (
  <div>
     {htmlFromCMS && htmlFrom(htmlFromCMS)}
  </div>
);


render(<App />, document.getElementById('root'));

Inspired by original post above, hence special thanks to original authors!

🌐
GitHub
github.com › wrakky › react-html-parser › issues › 54
Does this support typescript? · Issue #54 · peternewnham/react-html-parser
December 2, 2018 - Try npm install @types/react-html-parser if it exists or add a new declaration (.d.ts) file containing declare module 'react-html-parser';
🌐
Medium
medium.com › @san.vuthy08 › html-react-parser-1d0df932303a
HTML REACT PARSER. An HTML to React parser that works on… | by San Vuthy | Medium
May 20, 2019 - Because the parser returns an array for adjacent elements, make sure it’s nested under a parent element when rendered: import React, { Component } from 'react'; import parse from 'html-react-parser';class App extends Component { render() { return <div>{parse('<p>sibling 1</p><p>sibling 2</p>')}</div>; } }
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 77334588 › parsing-html5-video-element-with-html-react-parser
typescript - Parsing HTML5 <video> element with html-react-parser - Stack Overflow
import parse, { Element, HTMLReactParserOptions } from "html-react-parser" import VideoPlayer from "@/components/video-player" export default function ArticleContent({ content }: { content: string }) { const parserOptions: HTMLReactParserOptions = { replace: (domNode) => { // Replace embedded <video> tags with <VideoPlayer> if (domNode instanceof Element && domNode.name === "video") { return <VideoPlayer src={domNode.<????
🌐
Yarn
yarnpkg.com › package
types/react-html-parser
March 3, 2025 - Yarn is a package manager that doubles down as project manager. Whether you work on simple projects or industry monorepos, whether you're an open source developer or an enterprise user, Yarn has your back · First package manager built specifically around workspaces, Yarn lets you split your ...
🌐
Socket
socket.dev › npm › package › html-react-parser
html-react-parser - npm Package Security Analysis - Socket.dev
Migrated to TypeScript. CommonJS imports require the .default key: const parse = require('html-react-parser').default;
🌐
GitHub
github.com › peternewnham › react-html-parser
GitHub - peternewnham/react-html-parser: Converts HTML strings directly into React components and provide a simple way to modify and replace the content. · GitHub
Converts standard HTML elements, attributes and inline styles into their React equivalents and provides a simple way to modify and replace the content.
Starred by 797 users
Forked by 103 users
Languages   JavaScript
🌐
CodeSandbox
codesandbox.io › examples › package › html-react-parser
html-react-parser examples - CodeSandbox
html-react-parser-typescript · remarkablemark · cryptoverse · react-leaflet-editable-popupAn editable popup component for react-leaflet · client · react-liquidjs · corinna-ai · router · tender-chatelet-3lyrp · zszq · react-leaflet-custom-componentscustom components for react leaflet v3 ·
🌐
CodeSandbox
codesandbox.io › s › 2y8wqoqoy
React html parser - CodeSandbox
January 29, 2020 - React html parser by rizalibnu using @material-ui/core, @material-ui/icons, react, react-dom, react-html-parser, react-scripts
Published   Dec 27, 2018
Author   rizalibnu
🌐
Snyk
snyk.io › advisor › html-react-parser › html-react-parser code examples
Top 5 html-react-parser Code Examples | Snyk
April 19, 2022 - // description: ( // // ), // preview: Parser(MOST_TIME_CONSUMING_PREVIEW), // controls: MostTimeConsumingTestCasesControls, // }, ]; export const WIDGETS_STATIC_PREVIEWS = { [FLAKY_TEST_CASES_TABLE]: Parser(FLAKY_TEST_CASES_TABLE_PREVIEW), [LAUNCHES_TABLE]: Parser(LAUNCHES_TABLE_PREVIEW), [MOST_FAILED_TEST_CASES_TABLE]: Parser(MOST_FAILED_TEST_CASES_TABLE_PREVIEW), [PROJECT_ACTIVITY]: Parser(PROJECT_ACTIVITY_PREVIEW), [UNIQUE_BUGS_TABLE]: Parser(UNIQUE_BUGS_TABLE_PREVIEW), /* [PRODUCT_STATUS]: Parser(PRODUCT_STATUS_PREVIEW), */ [MOST_POPULAR_PATTERNS]: Parser(MOST_POPULAR_PATTERNS_PREVIEW), [CUMULATIVE_TREND]: Parser(CUMULATIVE_TREND_PREVIEW), [COMPONENT_HEALTH_CHECK]: Parser(COMPONENT_HEALTH_CHECK_PREVIEW), // [MOST_TIME_CONSUMING]: Parser(MOST_TIME_CONSUMING_PREVIEW), };
🌐
Npm
npm.io › package › html-react-parser
Html-react-parser NPM | npm.io
January 5, 2013 - Migrated to TypeScript. CommonJS imports require the .default key: const parse = require('html-react-parser').default;