htmlparser2 is a fast and forgiving HTML and XML parser written in TypeScript.
The tool addresses the need for rapid parsing of HTML and XML documents while prioritizing speed over strict specification compliance. It provides a callback-based interface that emits parser events as it processes documents, allowing consumers to handle opening tags, closing tags, text content, comments, CDATA sections, processing instructions, and errors with minimal memory overhead. This event-driven approach enables streaming-style consumption of documents without requiring the entire parse tree to be held in memory at once.
Developers should choose htmlparser2 if performance is a priority and they can tolerate lenient parsing behavior. It suits projects that need to process large volumes of HTML or XML quickly, such as web scrapers, feed readers, or build tools. The project explicitly acknowledges that if strict HTML specification compliance is required, parse5 is a better alternative. For ergonomic DOM manipulation, the tool integrates with a broader ecosystem including domhandler for DOM construction, domutils for DOM utilities, css-select for CSS selector support, and cheerio for a jQuery-like API.
The project maintains active engagement with its codebase through regular updates and refinements. Development shows consistent attention to performance optimization and parser correctness. The tool receives ongoing maintenance that addresses edge cases and parser behavior improvements. Community contributions are actively reviewed and integrated into the codebase.