Skip to content

react-markdown

A React component that renders Markdown text as React elements, without raw HTML injection.

Stars
15.9k
Forks
920
Licence
MIT
Language
JavaScript
Last update
1 months ago
Type
Library

What it is

react-markdown is a React component you give a string of Markdown, and it turns that text into React elements on the page. It avoids dangerouslySetInnerHTML, so it is designed to be safe by default against XSS. You can add plugins to change how Markdown is processed and swap normal HTML tags for your own React components.

  • Render a Markdown string from an API as formatted content in a React page
  • Add GitHub-style tables and task lists by passing remark-gfm as a remark plugin
  • Replace rendered headings or links with your own React components
  • Restrict which HTML tags can appear by using allowedElements or disallowedElements

Great for

  • React developers who need to display Markdown content such as comments, docs, or posts
  • Beginners who want safe Markdown rendering without writing HTML parsing code
  • Projects that want to replace rendered tags like h2 with custom React components
  • Teams that need GitHub Flavored Markdown tables, task lists, or strikethrough via a plugin

Not ideal for

  • People who want JavaScript or JSX embedded inside Markdown files; the README points to MDX for that
  • Developers who already know unified well and want a hooks-based alternative; the README points to react-remark or rehype-react
  • Projects that are not using React
Step-by-step guide: how to use react-markdownInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js 16+ · React

    Install with npm

    npm install react-markdown
  2. 2

    Run it

    • Install the package with npm install react-markdown
    • Import Markdown from 'react-markdown' in your React component
    • Render it with <Markdown>{markdown}</Markdown>, passing your Markdown string as children
    • Optionally add remarkPlugins={[remarkGfm]} to enable extra syntax
  3. 3

    Get the most out of it

    • Add remark-gfm through the remarkPlugins prop for tables, strikethrough, footnotes, and task lists
    • Use the components prop to map tags like h2 or a to your own React components
    • Use allowElement, allowedElements, or disallowedElements to filter which elements appear
    • Use MarkdownHooks when you need async plugins on the client, with a fallback prop while processing

Downloads

Strengths

  • Safe by default, with no dangerouslySetInnerHTML needed according to the README
  • Lets you replace rendered elements with custom React components
  • Supports plugins from the unified ecosystem such as remark-gfm

Trade-offs

  • The package is ESM only, which may need configuration in older build setups
  • Async plugins need MarkdownAsync or MarkdownHooks rather than the basic synchronous component
  • Full GFM support requires adding a separate plugin

How it compares

ProjectStarsTypeLevelUpdatedBest for
react-markdown (this)15.9kLibrarybeginner1 months agoReact developers who need to display Markdown content such as comments, docs, or posts
mdx19.8kLibraryintermediate7 days agoDevelopers building documentation or content sites in React, Preact, or Vue
tui.editor18kLibraryintermediate2.3 years agoWeb developers who want an embeddable Markdown editor in their own site or app
turndown11.5kLibrarybeginner19 days agoDevelopers who need to convert HTML content, such as web pages or rich text editor output, into Markdown
vditor11.4kLibraryintermediate19 days agoDevelopers who want to embed a Markdown editor in a web app
markdown-it22kLibraryintermediate13 days agoJavaScript or TypeScript developers who need to render Markdown in a Node.js or browser project

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.