<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c" -->

---
title: How to safely use dangerouslySetInnerHTML in React
description: Learn about the usage of dangerouslySetInnerHTML in React and how to safely use it. Avoid using it unless necessary and always sanitize the HTML before setting...
canonical: https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to safely use dangerouslySetInnerHTML in React | daily.dev
og:description: Learn about the usage of dangerouslySetInnerHTML in React and how to safely use it. Avoid using it unless necessary and always sanitize the HTML before setting...
og:url: https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c
og:image: https://api.daily.dev/og/posts/Deybtdu2C.png
og:image:alt: How to safely use dangerouslySetInnerHTML in React
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to safely use dangerouslySetInnerHTML in React

**[Community Picks](https://daily.dev/sources/community)** · 10 min read · 35 upvotes · 1 comments

## Summary

Learn about the usage of dangerouslySetInnerHTML in React and how to safely use it. Avoid using it unless necessary and always sanitize the HTML before setting it with dangerouslySetInnerHTML.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://deadsimplechat.com/blog/how-to-safely-use-dangerouslysetinnerhtml-in-react/>

## Community discussion

Top comments from developers on daily.dev.

**@floatrx** · 2 upvotes

> I really don't understand why we need one more extra library just to remove useless HTML. I prefer to use regex. And for Markdown, I use react-markdown. Last also supports custom handle render custom components! But thx for sharing.

---

Tags: [#react](https://daily.dev/tags/react), [#jsx](https://daily.dev/tags/jsx)

[View this post on daily.dev](https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to safely use dangerouslySetInnerHTML in React","url":"https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c"},"datePublished":"2024-03-14T15:05:43.707Z","dateModified":"2024-05-09T08:20:02.615Z","description":"Learn about the usage of dangerouslySetInnerHTML in React and how to safely use it. Avoid using it unless necessary and always sanitize the HTML before setting...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6103fc95d0f5e1e1267379d8b26586df?_a=AQAEufR","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6103fc95d0f5e1e1267379d8b26586df?_a=AQAEufR","isAccessibleForFree":true,"articleSection":"Community Picks","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Community Picks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1655817725/logos/community","url":"https://daily.dev/sources/community"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":35},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"react,jsx","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Community Picks","item":"https://daily.dev/sources/community"},{"@type":"ListItem","position":3,"name":"How to safely use dangerouslySetInnerHTML in React"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c","comment":[{"@type":"Comment","text":"I really don’t understand why we need one more extra library just to remove useless HTML. I prefer to use regex. And for Markdown, I use react-markdown. Last also supports custom handle render custom components! But thx for sharing.","datePublished":"2024-03-16T15:11:09.911Z","url":"https://daily.dev/posts/Deybtdu2C#c-ecOZzMu8c","author":{"@type":"Person","name":"Andrew","url":"https://daily.dev/floatrx","image":"https://lh3.googleusercontent.com/a/ACg8ocJmeqfWWSgNVSBNo5yHNlxRVSjHW3LPQaJH5gN4PJkd7fPJ=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}}]}
```

