Gathering detailed insights and metrics for html-dom-parser
Gathering detailed insights and metrics for html-dom-parser
Gathering detailed insights and metrics for html-dom-parser
Gathering detailed insights and metrics for html-dom-parser
npm install html-dom-parser
Typescript
Module System
Node Version
NPM Version
98.5
Supply Chain
99.6
Quality
84.6
Maintenance
100
Vulnerability
100
License
JavaScript (56.69%)
TypeScript (41.34%)
HTML (1.97%)
Total Downloads
233,276,489
Last Day
57,601
Last Week
1,830,110
Last Month
7,937,003
Last Year
81,455,198
MIT License
100 Stars
1,819 Commits
24 Forks
2 Watchers
1 Branches
9 Contributors
Updated on Jul 02, 2025
Minified
Minified + Gzipped
Latest Version
5.1.1
Package Id
html-dom-parser@5.1.1
Unpacked Size
128.73 kB
Size
29.57 kB
File Count
54
NPM Version
10.8.2
Node Version
20.19.1
Published on
May 09, 2025
Cumulative downloads
Total Downloads
Last Day
1.5%
57,601
Compared to previous day
Last Week
-7.5%
1,830,110
Compared to previous week
Last Month
1.1%
7,937,003
Compared to previous month
Last Year
32.6%
81,455,198
Compared to previous year
2
41
HTML to DOM parser that works on both the server (Node.js) and the client (browser):
HTMLDOMParser(string[, options])
The parser converts an HTML string to a JavaScript object that describes the DOM tree.
1import parse from 'html-dom-parser'; 2 3parse('<p>Hello, World!</p>');
1[ 2 Element { 3 type: 'tag', 4 parent: null, 5 prev: null, 6 next: null, 7 startIndex: null, 8 endIndex: null, 9 children: [ 10 Text { 11 type: 'text', 12 parent: [Circular], 13 prev: null, 14 next: null, 15 startIndex: null, 16 endIndex: null, 17 data: 'Hello, World!' 18 } 19 ], 20 name: 'p', 21 attribs: {} 22 } 23]
NPM:
1npm install html-dom-parser --save
Yarn:
1yarn add html-dom-parser
CDN:
1<script src="https://unpkg.com/html-dom-parser@latest/dist/html-dom-parser.min.js"></script> 2<script> 3 window.HTMLDOMParser(/* string */); 4</script>
Import with ES Modules:
1import parse from 'html-dom-parser';
Require with CommonJS:
1const parse = require('html-dom-parser').default;
Parse empty string:
1parse('');
Output:
1[]
Parse string:
1parse('Hello, World!');
1[ 2 Text { 3 type: 'text', 4 parent: null, 5 prev: null, 6 next: null, 7 startIndex: null, 8 endIndex: null, 9 data: 'Hello, World!' 10 } 11]
Parse element with attributes:
1parse('<p class="foo" style="color: #bada55">Hello, <em>world</em>!</p>');
1[ 2 Element { 3 type: 'tag', 4 parent: null, 5 prev: null, 6 next: null, 7 startIndex: null, 8 endIndex: null, 9 children: [ [Text], [Element], [Text] ], 10 name: 'p', 11 attribs: { class: 'foo', style: 'color: #bada55' } 12 } 13]
The server parser is a wrapper of htmlparser2 parseDOM
but with the root parent node excluded. The next section shows the available options you can use with the server parse.
The client parser mimics the server parser by using the DOM API to parse the HTML string.
Because the server parser is a wrapper of htmlparser2, which implements domhandler, you can alter how the server parser parses your code with the following options:
1/** 2 * These are the default options being used if you omit the optional options object. 3 * htmlparser2 will use the same options object for its domhandler so the options 4 * should be combined into a single object like so: 5 */ 6const options = { 7 /** 8 * Options for the domhandler class. 9 * https://github.com/fb55/domhandler/blob/master/src/index.ts#L16 10 */ 11 withStartIndices: false, 12 withEndIndices: false, 13 xmlMode: false, 14 /** 15 * Options for the htmlparser2 class. 16 * https://github.com/fb55/htmlparser2/blob/master/src/Parser.ts#L104 17 */ 18 xmlMode: false, // Will overwrite what is used for the domhandler, otherwise inherited. 19 decodeEntities: true, 20 lowerCaseTags: true, // !xmlMode by default 21 lowerCaseAttributeNames: true, // !xmlMode by default 22 recognizeCDATA: false, // xmlMode by default 23 recognizeSelfClosing: false, // xmlMode by default 24 Tokenizer: Tokenizer, 25};
If you're parsing SVG, you can set lowerCaseTags
to true
without having to enable xmlMode
. This will return all tag names in camelCase and not the HTML standard of lowercase.
[!NOTE] If you're parsing code client-side (in-browser), you cannot control the parsing options. Client-side parsing automatically handles returning some HTML tags in camelCase, such as specific SVG elements, but returns all other tags lowercased according to the HTML standard.
Migrated to TypeScript. CommonJS imports require the .default
key:
1const parse = require('html-dom-parser').default;
Upgraded htmlparser2 to v9.
Upgraded domhandler to v5. Parser options like normalizeWhitespace
have been removed.
Removed Internet Explorer (IE11) support.
Upgraded domhandler
to v4 and htmlparser2
to v6.
Release and publish are automated by Release Please.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
30 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool is run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
9 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More