Categories
React Answers

How to render HTML string as real HTML with React?

Spread the love

To render HTML string as real HTML with React, we use the dangerouslySetInnerHTML prop.

For instance, we write

<div dangerouslySetInnerHTML={{ __html: htmlString }} />;

to add a div with the dangerouslySetInnerHTML prop set to an object with the __html property set to the htmlString string.

Then htmlString is rendered as HTML.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *