API Reference

parse5

A spec-compliant HTML5 parser used by jsdom and Angular, producing a tree matching the WHATWG algorithm.

Official Documentation ↗
CompatibilityThis documentation covers version v7. Check the official docs for the latest API surface.

Installation

npmnpm install parse5

Methods

parse5 implements the HTML5 tree construction algorithm, matching browser error recovery for malformed markup.

Key Features

  • Spec-compliant tree construction
  • Fragment parsing in a context element
  • Serialization and custom tree adapters

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

API reference evidence

Fetched from official sources on 2026-11-08T17:51:20+08:00 via WebFetch https://parse5.js.org/functions/parse5.parse.html.

FAQ

Why not use a regex to parse HTML?
HTML error recovery is context sensitive and heavily specified. A compliant parser such as parse5 handles malformed markup the way browsers do.
Does parse5 execute scripts?
No. It only builds the tree; script execution and layout require a full environment such as jsdom.
How do I get htmlparser2-style nodes?
Provide the parse5-htmlparser2-tree-adapter as treeAdapter to get compatible nodes while keeping the spec parser.