html-react-parser

Converts HTML strings into React elements, working seamlessly on both server and client

Library
npm
v6.1.8
2,429 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
87 /100 Excellent
Development Activity 96
Maintenance 96
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 82
Code Quality 88
Innovation 78
Learning Curve 85

html-react-parser is a lightweight TypeScript library that converts raw HTML strings into React elements at runtime. It runs identically in Node.js (SSR) and in the browser, making it useful anywhere HTML content needs to be rendered as native React nodes rather than injected via dangerouslySetInnerHTML.

The library exposes a single default-export function alongside a replace option for swapping specific DOM elements with custom React components, and a transform option for per-node transformation during traversal. It builds on html-dom-parser (a wrapper around htmlparser2) for parsing and style-to-js for inline style conversion, keeping the dependency surface small while supporting custom parsing engines.

What You Get

  • A single parse(html, options) function that returns React elements, an array of elements, or a string
  • A replace option to swap matched DOM nodes with custom React components or remove them
  • A transform option for per-node transformation during the HTML-to-React walk
  • Works identically during server-side rendering and in the browser
  • TypeScript types shipped in the package, plus CJS, ESM, and UMD builds

Common Use Cases

  • Rendering HTML fetched from a headless CMS as native React elements instead of raw innerHTML
  • Replacing specific tags (e.g. <a>, <img>) with custom React components while parsing rich content
  • Server-rendering HTML fragments in a Next.js or other SSR app without a client-only DOM dependency
  • Post-processing markdown-rendered HTML to inject interactive React components

Under The Hood

Architecture The library is a thin three-stage pipeline: html-dom-parser (an htmlparser2 wrapper) parses the input HTML string into a DOM node tree, dom-to-react.ts recursively walks that tree converting each DOMNode into React.createElement calls (handling replace/transform hooks per node), and attributes-to-props.ts maps HTML attributes/inline styles to React props (via style-to-js and react-property for attribute-name mapping). The public surface is a single default export (src/index.ts, 40 lines) that wires these stages together, keeping the whole conversion synchronous and dependency-light.

Tech Stack Written in TypeScript, built with tsc for CJS and Rollup for a UMD bundle, targeting both CJS and ESM consumers via package.json exports. Runtime dependencies are minimal and pinned exactly: domhandler, html-dom-parser, react-property, style-to-js. Tests run on Vitest (including a browser mode via Playwright for real-DOM verification), linting via ESLint 10 with typescript-eslint, and releases are automated with conventional commits and changelog generation.

Code Quality The __tests__ directory mirrors src/ one-to-one (dom-to-react, attributes-to-props, utilities.test.ts, plus an integration/ suite and browser-mode tests), and CI runs both Node and browser test targets plus arethetypeswrong and publint to verify package exports are correct. Source files are small and single-purpose (40-182 lines each), fully typed with exported HTMLReactParserOptions, and the entry point throws a TypeError on non-string input rather than failing silently.

API Design The API is a single default function with an optional second options argument, so the zero-config path (parse(html)) requires no setup. Power users get two well-documented escape hatches (replace, transform) without needing to learn a plugin system, and the package re-exports the underlying DOM node types (Comment, Element, Text) so consumers can type-narrow inside replace callbacks. The extensive README with a table of contents, FAQ, and migration guides for five major versions materially lowers the learning curve.

Used by 9 apps in this directory

TypeScript
72%
AGPL 3.0

APITable

Databases · Low Code Platforms

15,623

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
71
Repo Health
77
Technical
60
Dependency
Built with
TypeScript 72%
Java 22%
Updated 3 weeks ago
TypeScript
99%
Other

byterover-cli

AI Agents · AI Code Assistants · AI Memory

4,966

A portable memory layer for AI coding agents — curate structured project knowledge into a version-controlled context tree that syncs across tools, machines, and teammates.

View details
50
Repo Health
83
Technical
70
Dependency
Built with
TypeScript 99%
Updated 3 months ago
TypeScript
94%
AGPL 3.0

Element Web

Collaboration · Team Chat

13,518

A polished, self-hostable Matrix client for secure, decentralized messaging and collaboration that puts your organization in full control of its data.

View details
96
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 94%
Updated 6 days ago
TypeScript
62%
Other

Flowise

AI Development · Automation · Developer Tools

55,490

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
82
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 62%
JavaScript 27%
Updated 1 months ago
TypeScript
39%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,358

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
TypeScript 39%
JavaScript 27%
Python 25%
Updated 5 days ago
JavaScript
43%
Other

LimeSurvey

Forms Surveys

3,736

The world's most flexible open-source survey platform with 900+ templates, conditional logic, 80+ languages, and full GDPR compliance for any scale.

View details
86
Repo Health
62
Technical
63
Dependency
Built with
JavaScript 43%
PHP 35%
CSS 12%
Updated 6 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,043

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
70
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 1 months ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

22,918

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
89
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 6 days ago
HTML
36%

OpenPanel

Devops · Hosting Control Panel

749

Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.

View details
84
Repo Health
75
Technical
63
Dependency
Built with
HTML 36%
Go 32%
TypeScript 23%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers