htmlparser2
A strong pick. 4th of 10 web scraping and HTML parsing.
htmlparser2 is a fast, forgiving, streaming HTML/XML parser that sits under Cheerio, sanitize-html and many other tools. It is a strong low-level pick when you need speed or streaming, but most scraping code is easier to write with Cheerio on top of it, and parse5 or jsdom fit better when you need a browser-exact tree.
Best for: Developers who need a very fast, streaming or callback-based HTML/XML parser, or who build their own tools on a light DOM.
Scores
Overall7.3
How strongly do we recommend it for a new project today?
Claude Opus 5.5: 7.0, likely 6.0 to 8.0
It is a fast, well-maintained and safe parser that much of the ecosystem trusts, and it is the best pick when you need low-level or streaming HTML/XML parsing. For typical scraping, Cheerio (built on it) is easier to use, and jsdom or parse5-based tools fit better when you need a spec-exact DOM. Its reliance on one maintainer and the recent breaking majors keep it from scoring higher.
- github.com/AndreasMadsen/htmlparser-benchmark/blob/master/README.md: It leads on speed.
- newreleases.io/project/yarn/htmlparser2/release/12.0.0: Active development with spec alignment.
- npm downloadsLast4Weeks: Huge use, mostly transitive.
GPT-6.2 Sol: 7.6, likely 6.5 to 8.6
htmlparser2 is a strong pick for a new project that needs fast streaming parses or direct access to parser events. Cheerio is a better default for fetching static pages and extracting fields with selectors, and Puppeteer fits pages that need to run JavaScript. The latest version still has browser-parsing differences, and the March release gap and mixed adoption signals temper the recommendation.
- github.com/fb55/htmlparser2/releases: Documents stream support, parsing fixes, and recent breaking changes.
- github.com/lukeed/html/blob/main/bench/readme.md: Measures practical speed and memory trade-offs on real pages.
- cheerio.js.org/docs/basics/loading: Cheerio includes URL loading for static scraping.
- pptr.dev: Puppeteer runs a browser for rendered pages.
- github latestRelease, npm downloadsLast4Weeks, npm downloadsSame4WeeksYearAgo, medianDownloadsRatio: Stable release dates to March, and download growth trails the catalog median.
Needed by many4.9
How many developers need a tool for this job?
Claude Opus 5.5: 5.0, likely 4.0 to 6.0
Many projects need to read HTML, but most developers reach for Cheerio, jsdom or a browser tool rather than a raw parser. htmlparser2 serves the smaller group that needs low-level, fast or streaming parsing. It runs in Node and in browsers and handles both HTML and XML, which widens it somewhat.
- scrapeops.io/nodejs-web-scraping-playbook/best-nodejs-html-parsing-libraries: Describes it as the low-level option next to Cheerio and jsdom.
- webscraping.fyi/lib/compare/javascript-cheerio-vs-javascript-htmlparser2: Cheerio is the usual scraping choice and builds on htmlparser2.
GPT-6.2 Sol: 4.8, likely 3.6 to 6.0
Scrapers, feed readers, and content processors all need to parse markup, and htmlparser2 works with strings and streams. Its low-level API mainly serves teams that already have the markup and want control over parsing. The feature boundaries are clear, but the evidence gives little sense of how many JavaScript teams need that level of control.
- github.com/fb55/htmlparser2: Documents callbacks, DOM helpers, and RSS and Atom parsing.
- cheerio.js.org/docs/basics/loading: Cheerio offers URL loading and several ways to load static markup.
- pptr.dev: Puppeteer controls a browser for pages that need rendering.
Helps a lot7.5
How well does it do the job for those who need it?
Claude Opus 5.5: 7.0, likely 6.0 to 8.0
It is very fast and forgiving, and it offers a streaming callback API, an optional DOM and XML mode, with built-in types. v12 brought tokenizing much closer to WHATWG. It is still not a full spec tree builder, and it needs helper packages or Cheerio for queries, so for many jobs it is a building block rather than a complete tool.
- github.com/AndreasMadsen/htmlparser-benchmark/blob/master/README.md: Independent benchmark: about 2.2 ms per file, against about 9.7 ms for parse5.
- newreleases.io/project/yarn/htmlparser2/release/12.0.0: v12 aligns raw-text, RCDATA, comment and foreign-content handling with WHATWG.
- npm hasTypes: Ships its own TypeScript types.
GPT-6.2 Sol: 8.0, likely 7.0 to 9.0
Version 12 offers typed callbacks and DOM building, and improves how it handles malformed markup. In a 12-page benchmark, it built trees about three times as fast as parse5 on Node and retained much less memory, though node-html-parser finished sooner. Browser-style tree construction remains a limitation, and text callbacks can arrive in pieces. The speed evidence depends on the workload, and the examples and types are easier to assess than the correctness of agent-generated code.
- github.com/fb55/htmlparser2/releases/tag/v12.0.0: Details parsing changes for raw text, comments, and foreign content.
- github.com/lukeed/html/blob/main/bench/readme.md: A competing parser's author published timing and retained-heap measurements on 12 real pages.
- cheerio.js.org/docs/advanced/configuring-cheerio: Documents the trade-off between forgiving parsing and browser-compatible trees.
- github.com/fb55/htmlparser2: Includes callback and DOM examples and explains split text events.
- npm hasTypes: Ships TypeScript declarations.
Holds up over time7.3
Will it still be a good choice in two years?
Claude Opus 5.5: 7.5, likely 6.5 to 8.5
The project is 15 years old and still active: 184 commits and 3 releases in the last year, only 4 open issues, and a fresh push. Releases depend mostly on one maintainer, and v11 (ESM only) and v12 (parsing changes) each broke some code. Cheerio and much of the ecosystem depend on it, which strongly pushes it to keep going.
- github commitsLastYear: 184 commits and 3 releases in the last year.
- github openIssues: 4 open issues against 316 closed.
- newreleases.io/project/yarn/htmlparser2/release/11.0.0: v11 went ESM-only and requires Node 20.19 or newer.
- fb55 maintainership: Felix Böhm maintains it, together with Cheerio, css-select, domutils and entities.
GPT-6.2 Sol: 7.0, likely 5.8 to 8.2
The repository recorded 184 commits and three releases over the past year, with work continuing after the March release. The ESM switch and changes to parsing behavior caused downstream upgrade work. Recent release activity centers on one visible maintainer, and the sponsorship link leaves funding and backup publishing access unclear. The small issue backlog gives limited evidence about response times.
- github commitsLastYear, releasesLastYear, pushedAt, openIssues, openPullRequests: 184 commits, three releases, a November push, four open issues, and ten open pull requests.
- github.com/fb55/htmlparser2/releases: Recent tags show the same visible releaser, an ESM migration, and changes to tree output.
- github.com/apostrophecms/apostrophe/issues/5525: Downstream users report integration failures on Lambda and Netlify.
- github.com/fb55/htmlparser2/blob/v12.0.0/package.json: Lists GitHub Sponsors for the maintainer.
Used widely6.8
How many use it, and is that growing?
Claude Opus 5.5: 7.0, likely 6.0 to 8.0
Downloads are huge, about 565M in 4 weeks, and ecosyste.ms counts 2.7M dependent repositories, but most of this comes through Cheerio, sanitize-html, html-react-parser and similar tools. Its ratio of about 3.1 is below the 4.1 median, so its share is slipping slightly. About 2,500 npm packages depend on it directly, which points to many thousands of direct choices.
- npm downloadsLast4Weeks: 565M now against 182M a year ago, a ratio of about 3.1, below the 4.1 median.
- dependents: 2.7M repositories and 2,492 packages, mostly transitive.
- peers Cheerio downloadsLast4Weeks: Cheerio's 143M downloads pass through to htmlparser2.
- bluesky posts: Only 1 post, so it draws little direct attention.
GPT-6.2 Sol: 6.6, likely 5.1 to 8.0
Four-week downloads rose from 182 million to 565 million, or 3.11 times the prior year, below the catalog median of 4.1 and jsdom's 4.20. The 2.7 million indexed repositories lead this peer set, and 2,492 indexed npm packages show broad use by other libraries. Tools such as Cheerio bring it into projects automatically, and older majors still account for much of weekly npm traffic. The direct share remains hard to estimate, and one Bluesky post offers little evidence of current adoption.
- npm downloadsLast4Weeks, npm downloadsSame4WeeksYearAgo, medianDownloadsRatio: 3.11 times year-over-year download growth against the catalog median of 4.1.
- dependents repos, dependents packages, peers dependentRepos, peers downloadsLast4Weeks, peers downloadsSame4WeeksYearAgo: Leads the peer set in indexed dependent repositories, while jsdom grows faster.
- bluesky posts, peers blueskyPosts: One post, compared with two for Cheerio and eleven for jsdom.
- cheerio.js.org/docs/advanced/configuring-cheerio: Cheerio ships htmlparser2 even though its main HTML loader defaults to parse5.
- npmjs.com/package/htmlparser2?activeTab=versions: Several older majors retain substantial weekly downloads.
Vouched for7.5
Who stands behind it being good?
Claude Opus 5.5: 7.0, likely 6.0 to 8.0
Widely used tools build on it, including Cheerio, sanitize-html, html-react-parser and eslint-plugin-html, and it is in the dependency trees of large production codebases. An independent benchmark confirms its speed. There is little survey or community discussion of it as a direct choice.
- github.com/AndreasMadsen/htmlparser-benchmark/blob/master/README.md: Independent benchmark across many parsers.
- npm-compare.com/cheerio,htmlparser2,jsdom,parse5: Compared as a core parser next to parse5, jsdom and Cheerio.
- cheerio/sanitize-html dependencies: Major libraries ship it as their parser.
GPT-6.2 Sol: 7.9, likely 6.7 to 8.9
Cheerio uses htmlparser2 for XML and for all parsing in its slim build. PostHTML's parser and sanitize-html both moved to version 12, and an external benchmark measured favorable memory use. These are concrete signs of trust in the parser, though the benchmark covers one corpus and there is little direct evidence of satisfaction among teams that install it themselves.
- cheerio.js.org/docs/advanced/configuring-cheerio: Uses htmlparser2 for XML and in the slim build.
- github.com/posthtml/posthtml-parser/blob/master/changelog.md: PostHTML's parser upgraded from version 9 to version 12 in October 2026.
- github.com/apostrophecms/apostrophe/blob/main/packages/sanitize-html/CHANGELOG.md: sanitize-html adopted version 12 to improve parsing in cases that affect sanitization.
- github.com/lukeed/html/blob/main/bench/readme.md: A competing parser's benchmark measured low retained heap for htmlparser2.
Safe8.1
How safe is it to depend on?
Claude Opus 5.5: 8.5, likely 7.5 to 9.0
It has no advisories ever recorded, an MIT licence, and only four dependencies, all from the same maintainer (domhandler, domutils, domelementtype, entities). Its Scorecard is 7.3, with weak token permissions, no fuzzing and partly pinned dependencies. Publishing depends mostly on one account.
- advisories total: 0 advisories.
- scorecard score: 7.3, with Token-Permissions and Fuzzing at 0.
- npm dependencies: 4 dependencies.
GPT-6.2 Sol: 7.6, likely 6.4 to 8.7
The MIT license, four direct dependencies, and zero recorded advisories for the package are positives. Version 12 corrected parser behavior that contributed to downstream sanitization bugs. OpenSSF scores code review and the security policy well, with zero scores for token permissions and fuzzing and partial credit for dependency pinning. Limited visibility into release signing and publishing access keeps the range wide.
- advisories total, npm dependencies, npm license: Zero recorded package advisories, four direct dependencies, and an MIT license.
- scorecard score, scorecard checks: 7.3 overall, with weak token permissions and fuzzing checks and no signed-release result.
- github.com/fb55/htmlparser2/releases/tag/v12.0.0: Version 12 improved parsing of raw text and foreign content.
- github.com/apostrophecms/apostrophe/blob/main/packages/sanitize-html/CHANGELOG.md: Documents downstream security fixes that used the newer parser alongside sanitizer changes.
Good
- In independent real-world benchmarks it is among the fastest HTML parsers in Node, about four times faster than parse5.
- You can use it as a streaming SAX-style parser or build a light DOM with domhandler, and it handles both HTML and XML.
- It has a small dependency tree of four packages from the same maintainer, no known advisories and built-in TypeScript types.
- It is still actively maintained: v12 brought tokenizing much closer to the WHATWG spec.
Bad
- It only parses. It does not fetch pages or run JavaScript, and it has no selectors unless you add css-select/domutils or use Cheerio.
- The output tree is still not fully spec-compliant. The maintainer points users to parse5 when the tree must match a browser's.
- Recent majors broke code: v11 dropped CommonJS and requires Node 20.19 or newer, and v12 changed how raw-text tags and entities are parsed.
- Releases depend mostly on one maintainer, Felix Böhm (fb55).
The numbers
- npm downloads, 4 weeks
- 565M ×3.1 in a year
- GitHub stars
- 4.8k
- Commits, 12 months
- 184
- npm version
- 12.0.0 Mar 2026
- Versions, 12 months
- 3
- Advisories, 24 months
- 0 of 0 ever
- OpenSSF Scorecard
- 7.3 out of 10, Nov 2026
- Licence
- MIT
Read on 21 November 2026 from GitHub (fb55/htmlparser2), npm (htmlparser2), OSV and the OpenSSF Scorecard.
Web scraping and HTML parsing
- 8.1Cheerio
- 7.9Puppeteer
- 7.8Crawlee
- 7.3htmlparser2
- 7.1jsdom
- 6.8Stagehand
- 6.8Readability
- 5.5Happy DOM
- 5.4LinkeDOM
- 5.2Selenium WebDriver