react-markdown turns Markdown strings into React elements without dangerouslySetInnerHTML. It uses remark and rehype plugins for GFM, syntax highlighting, and optional HTML handling.
Overview
react-markdown is a React component that accepts a Markdown string and produces a React element tree. It avoids injecting raw HTML by default and builds a virtual DOM so React can update only what changed when content edits.
Processing follows the unified pipeline: Markdown parses to an mdast tree, remark plugins transform it, remark-rehype converts to hast, rehype plugins adjust HTML, and custom components map tags to React elements. CommonMark compliance is the default; GitHub Flavored Markdown features such as tables, task lists, strikethrough, and autolinks arrive through plugins like remark-gfm.
Developers can swap components for headings, links, code blocks, and other tags, attach remark and rehype plugins, filter allowed elements, and customize URL sanitization. Separate exports support synchronous rendering, async plugins on the server, and hook-based client rendering with fallbacks.
The package is ESM-only and targets maintained Node releases plus modern browsers via bundlers. Security guidance recommends rehype-sanitize when enabling raw HTML plugins such as rehype-raw.
Key features
- Markdown to React elements without raw HTML by default
- remark and rehype plugin pipeline
- Custom component mapping for Markdown tags
- Optional GFM via remark-gfm
- Configurable URL transform and element filters
- Sync, async, and hooks-based render modes
- CommonMark-oriented parsing via micromark
- Plugin ecosystem for math and highlighting
Use cases
- Rendering user Markdown in React apps
- Docs or comment UI with GFM tables
- Custom-styled Markdown headings and links
- Syntax-highlighted code blocks via rehype plugins
- Sanitized HTML Markdown when explicitly enabled