🌐
npm
npmjs.com › package › html-react-parser
html-react-parser - npm
3 weeks ago - The parser converts an HTML string to one or more React elements.
      » npm install html-react-parser
    
Published   Apr 08, 2026
Version   6.0.1
🌐
npm
npmjs.com › package › react-html-parser
react-html-parser - npm
November 29, 2017 - Parse HTML into React components. Latest version: 2.0.2, last published: 8 years ago. Start using react-html-parser in your project by running `npm i react-html-parser`. There are 473 other projects in the npm registry using react-html-parser.
      » npm install react-html-parser
    
Published   Nov 29, 2017
Version   2.0.2
Author   Peter Newnham
🌐
npm
npmjs.com › search
html-react-parser - npm search
A very fast HTML parser, generating a simplified DOM, with basic element query support. ... taoqf• 7.1.0 • 2 months ago • 1961 dependents • MITpublished version 7.1.0, 2 months ago1961 dependents licensed under $MIT ... HTML to React parser.
🌐
npm
npmjs.com › package › @types › react-html-parser
@types/react-html-parser - npm
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
github.com › remarkablemark › html-react-parser
GitHub - remarkablemark/html-react-parser: 📝 HTML to React parser.
Parser throws an error · Is SSR supported? Elements aren't nested correctly · Don't change case of tags · TS Error: Property 'attribs' does not exist on type 'DOMNode' Can I enable trim for certain elements? Webpack build warnings · TypeScript error · Performance · Contributors · Code Contributors · Financial Contributors · Individuals · Organizations · Support · License · NPM: npm install html-react-parser --save ·
Starred by 2.4K users
Forked by 139 users
Languages   TypeScript 87.9% | JavaScript 12.1%
🌐
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), };
🌐
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
🌐
GitHub
github.com › remarkablemark › html-react-parser › issues › 1501
html-react-parser with React 19 · Issue #1501 · remarkablemark/html-react-parser
August 27, 2024 - Error Details: When attempting to install or use html-react-parser with React 19, npm reports a peer dependency conflict.
Author   AlessandroGasperini
🌐
npm
npmjs.com › package › react-native-html-parser
react-native-html-parser - npm
February 4, 2020 - Latest version: 0.1.0, last published: 6 years ago. Start using react-native-html-parser in your project by running `npm i react-native-html-parser`. There are 9 other projects in the npm registry using react-native-html-parser.
      » npm install react-native-html-parser
    
Published   Feb 04, 2020
Version   0.1.0
Author   Cheol
🌐
npm
npmjs.com › package › @burst › react-html-parser
@burst/react-html-parser - npm
import reactHtmlParser from '@burst/react-html-parser'; render( <ReactHTMLParser components={{}}>{'<p>Hello</p>'}</ReactHTMLParser>, );
      » npm install @burst/react-html-parser
    
Published   Sep 12, 2022
Version   1.0.4
Author   Jori Regter
🌐
CodeSandbox
codesandbox.io › s › html-react-parser-940pov1l4w
html-react-parser - CodeSandbox
February 13, 2024 - CodeSandbox is a cloud development platform that empowers developers to code, collaborate and ship projects of any size from any device in record time.
Published   Jan 08, 2019
Author   remarkablemark
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!

🌐
DEV Community
dev.to › kalush89 › how-to-parse-html-string-in-react-53fh
How to Parse HTML string in React - DEV Community
February 21, 2023 - react-html-parser According to this npm package's Readme, it converts standard HTML elements, attributes, and inline styles into their React equivalents
🌐
Npm
npm.io › package › html-react-parser
Html-react-parser NPM | npm.io
January 5, 2013 - The parser converts an HTML string to one or more React elements.
🌐
Npm
npm.io › package › html-parser-react-lison
Html-parser-react-lison NPM | npm.io
var parse = require('html-react-parser'); parse('<div>text</div>'); // equivalent to `React.createElement('div', {}, 'text')`
🌐
Npm
npm.io › package › react-html-parser
React-html-parser NPM | npm.io
A utility for converting HTML strings into React components.