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
npm
npm install parse5Methods
No methods match this filter.
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.
parse→ signature from https://parse5.js.org/functions/parse5.parse.html; official text: “html: string, options?: ParserOptions, ): T[“document”]” parseFragment→ signature from https://parse5.js.org/functions/parse5.parseFragment.html; official text: “fragmentContext: T[“parentNode”] | null, html: string, options: ParserOptions, ): T[“documentFragment”]” serialize→ signature from https://parse5.js.org/functions/parse5.serialize.html; official text: “node: T[“parentNode”], options?: SerializerOptions, ): string”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.