JavaScript HTML parser libraries

Updated Nov 2026

JavaScript HTML parser libraries turn HTML text into a tree of nodes that code can query, change, and serialize. A full DOM implementation exposes browser APIs such as querySelector, while a lighter parser returns a plain tree or a stream of parse events. These libraries extract data from scraped pages, transform HTML in build pipelines, and run browser-style tests.

Popularity

parse5 has the most monthly downloads in this comparison, at 910.8M.

LibraryMonthly downloadsStarsLast releaseLicense
parse5
910.8M
3.9KNov 2026MIT
jsdom
603.4M
21.8KNov 2026MIT
htmlparser2
542.3M
4.8KMar 2026MIT
Cheerio
138.0M
30.5KJan 2026MIT
Happy DOM
130.1M
4.8KOct 2026MIT
html-parse-stringify
92.9M
3Jul 2026MIT
hast-util-from-html
83.9M
42Nov 2026MIT
node-html-parser
57.8M
1.2KNov 2026MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Parses and serializes HTML using the WHATWG HTML standard.

Downloads / mo
910.8M
Stars
3.9K
Last release
8.1.1
License
MIT

Strengths

  • Uses browser parsing rules. Build HTML trees using the HTML Living Standard.
  • Parses fragments with context. Pass a context element to parse fragment content as innerHTML.

Limitations

  • Inserted nodes lack source locations. Implicitly created tree-correction elements have undefined sourceCodeLocation.
  • Streaming needs another package. Install parse5-parser-stream for the streaming parser.

Quickstart

From index.ts
$ npm install parse5
import { parse } from 'parse5';

const document = parse('<p>Hello</p>');

parse5 examples

From open-source projects on GitHub

Provides DOM objects for working with parsed HTML in Node.js.

Downloads / mo
603.4M
Stars
21.8K
Last release
31.0.1
License
MIT

Strengths

  • Exposes familiar DOM selectors. Use document.querySelector on the parsed document.
  • Retains optional source locations. Enable includeNodeLocations and retrieve positions with nodeLocation.

Limitations

  • Layout measurements are incomplete. Layout-related properties can return zeros instead of browser measurements.
  • Link navigation stays unimplemented. Changing location.href does not create a new document.

Quickstart

From README.md
$ npm install jsdom
const { JSDOM } = require('jsdom');

const dom = new JSDOM('<p>Hello</p>');
const text = dom.window.document.querySelector('p').textContent;

htmlparser2

Parses HTML and XML using event callbacks or a document tree.

Downloads / mo
542.3M
Stars
4.8K
Last release
12.0.0
License
MIT

Strengths

  • Processes input in chunks. Feed markup through Parser.write before ending the input.
  • Serializes edited trees. Use the exported DomUtils.getOuterHTML to serialize changed HTML.

Limitations

  • Browser tree rules differ. Choose parse5 when strict HTML specification compliance matters.
  • Text callbacks can split content. Join text pieces when one callback does not contain the whole section.

Quickstart

From README.md
$ npm install htmlparser2
import { parseDocument } from 'htmlparser2';

const document = parseDocument('<p>Hello</p>');

Parses HTML and XML with a jQuery-like selection and editing API.

Downloads / mo
138.0M
Stars
30.5K
Last release
1.2.0
License
MIT

Strengths

  • Selects elements with CSS. Call the returned dollar function with a CSS selector.
  • Reads byte streams with encoding. Use decodeStream when the source encoding is unknown.

Limitations

  • Client-rendered content stays absent. Cheerio does not execute the scripts that create client-rendered content.
  • Browser builds only load strings. Buffer, stream, and URL loaders require Node.js.

Quickstart

From Readme.md
$ npm install cheerio
import * as cheerio from 'cheerio';

const $ = cheerio.load('<h1>Hello</h1>');
const text = $('h1').text();

Cheerio examples

From open-source projects on GitHub

Happy DOM

Implements a web browser without a graphical interface, including many WHATWG DOM and HTML standards.

Downloads / mo
130.1M
Stars
4.8K
Last release
21.0.4
License
MIT

Strengths

  • Simulates a browser or a window. The Browser class loads pages, while the Window class builds a DOM directly.
  • Supports custom elements. Custom elements with declarative shadow DOM work inside the simulated document.

Limitations

  • Scripts are off by default. Turn on JavaScript evaluation only for trusted code, because its VM contexts are not isolated.

Quickstart

From Window.md
$ npm install happy-dom
import { Window } from 'happy-dom';

const window = new Window();
window.document.body.innerHTML = '<p>Hello</p>';
const text = window.document.querySelector('p').textContent;
await window.happyDOM.close();

html-parse-stringify

Parses well-formed HTML, with every tag closed, into an AST and back.

Downloads / mo
92.9M
Stars
3
Last release
4.0.1
License
MIT

Strengths

  • Round-trips HTML strings. Stringify turns the parsed AST back into the original HTML string.
  • Powers the Trans component. The i18next community maintains it as the parser behind Trans in react-i18next.

Limitations

  • Requires closed tags. Close or self-close every tag before parsing.

Quickstart

From README.md
$ npm install html-parse-stringify
import HTML from 'html-parse-stringify';

const nodes = HTML.parse('<p>Hello</p>');

html-parse-stringify examples

From open-source projects on GitHub

hast-util-from-html

Turns HTML into a hast syntax tree.

Downloads / mo
83.9M
Stars
42
Last release
2.1.0
License
MIT

Strengths

  • Parses fragments or documents. Set fragment to true to parse a snippet instead of a whole document.
  • Records detailed positions. The verbose option records positions for attributes, start tags, and end tags.

Limitations

  • Output is not sanitized. Run hast-util-sanitize on the tree before rendering user-provided HTML.

Quickstart

From readme.md
$ npm install hast-util-from-html
import { fromHtml } from 'hast-util-from-html';

const tree = fromHtml('<p>Hello</p>', { fragment: true });

hast-util-from-html examples

From open-source projects on GitHub

node-html-parser

Parses HTML into a simplified DOM tree with element queries.

Downloads / mo
57.8M
Stars
1.2K
Last release
9.0.7
License
MIT

Strengths

  • Supports querySelector. Query the parsed tree with CSS selectors through querySelector.
  • Serializes back to HTML. Call toString on the root to write the tree back out as HTML.

Limitations

  • Some malformed HTML misparses. Expect parse errors on some malformed HTML beyond common cases such as unclosed table cells.

Quickstart

From README.md
$ npm install node-html-parser
import { parse } from 'node-html-parser';

const root = parse('<p>Hello</p>');
const text = root.querySelector('p').textContent;

node-html-parser examples

From open-source projects on GitHub

FAQ

parse5 follows the HTML Living Standard and fits code that needs browser-accurate trees. Cheerio adds a jQuery-like API for selecting and editing elements. jsdom and Happy DOM supply a DOM with browser APIs, while htmlparser2 emits parse events as markup arrives.

Cheerio parses HTML and XML and gives a jQuery-like API for traversing and changing the result. It does not render pages, load external resources, or run JavaScript.

jsdom is a pure-JavaScript implementation of the WHATWG DOM and HTML standards for Node.js. It returns zeros for many layout properties and does not navigate when location.href changes.

Cheerio parses markup into a tree with a jQuery-like API and skips rendering, CSS, and scripts. jsdom builds a browser-style DOM, with objects such as window and document.querySelector.

Happy DOM implements a web browser without a graphical interface, including many WHATWG DOM and HTML standards. It works as a test environment for tools such as Vitest and Jest, and it runs scripts only when JavaScript evaluation is turned on.

No. Content that client-side scripts render never reaches Cheerio's tree, because Cheerio does not run JavaScript.

For coding agents

Found your HTML parser library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official