HTML Conformance: A Comparison of 6.5 npm Validator Packages (With 1.5 Recommendations)
Published on Dec 17, 2024 (updated Jan 6, 2025), filed under development, html, conformance (feed). (Share this on Mastodon or Bluesky?)
Itâs easy to validate the output of an HTML document using the W3C HTML validator or its Validator.nu sibling. As web-based tools, they donât require any setup.
But what if you cannot use these validators? What if you have to or choose to resort to a package? Would you even have an alternative?
I reviewed what seemed to be the six most popular validator packages on npm, plus a âstatic code analysis toolâ for HTML, to check on how useful these actually are. (Jump to the summary if you either care about a quick comparison or snippet validation in particular.)
The Reviews
HTML-validate
- Notes: To be useful to work with HTMLâHTML (as opposed to XHTMLâHTML), HTML-validate requires opting into its âstandardâ preset
- Issues: Even with the standard preset, HTML validation isnât at parity with the W3C validatorâfor example, optional tags arenât currently handled correctly, and missing
lang
attributes are handled too strictly - Recommendation: đĄ/đ˘âuntil some reported issues are fixed, use HTML-validate if youâre writing XHTMLâHTML, and donât mind addressing HTML issues you donât normally have to address
W3C HTML Validator
- Notes: W3C HTML Validator (not an official W3C tool, from what I can tell) tests against the web-based W3C validator
- Issues: Quickly runs into W3C rate limits
- Recommendation: đĄâcan be acceptable for limited validation (npx w3c-html-validator .)
html-w3c-validator
- Notes: Not an official W3C tool, either; requires a config file; seems to test against the web-based W3C validator (perhaps with modifications)
- Issues: Throws false positives, as around file encodings
- Recommendation: đĄ/đ´âneeds adjustments for local validation
html-validator
- Notes: Requires a config file, tests against the web-based W3C validator
- Issues: Quickly runs into W3C rate limits, seems to be configured very/too strictly (warnings as errors); project seems unmaintained
- Recommendation: đĄâacceptable for isolated remote validation (npx site-validator-cli https://example.com/)
The Nu Html Checker (v.Nu)
- Notes: Requires local installation and a config file⌠or working with Java
- If you want to go down the Java route, hereâs one quick runbook: install package globally (npm i -g vnu-jar); if not installed yet, install Java; if needed, switch the Java version; consider setting up an alias (mine, hacky, for local validation of entire folders:
alias v="java -jar /Users/USER/.nvm/versions/Ânode/*/lib/node_modules/vnu-jar/Âbuild/dist/vnu.jar --errors-only --skip-non-html .
)
- If you want to go down the Java route, hereâs one quick runbook: install package globally (npm i -g vnu-jar); if not installed yet, install Java; if needed, switch the Java version; consider setting up an alias (mine, hacky, for local validation of entire folders:
- Recommendation: đ˘âgo for it, though if you need HTML snippet/fragment support, this isnât it (check the summary)
html-validator
- Notes: Requires local installation and a config file, which had me skip a more detailed review
- Issues: Project seems unmaintained
HTMLHint
- Notes: Plays well with npx (npx htmlhint *)
- Issues: Defaults seem strict, needs configuration, which in turn seems to be based on opting into rules, not opting out (my config, based on rules documentation: npx htmlhint ârules title-require attr-no-duplication attr-whitespace alt-require input-requires-label tags-check tagname-specialchars src-not-empty id-class-value id-unique space-tab-mixed-disabled *); project seems unmaintained
- Recommendation: đ´âHTMLHint is a linter rather than a validator, and even if it was a validator, it seems too easy to misconfigure given the need to opt into rules
A Summary
Package | Can handle HTMLâHTML? | Can handle HTML snippets? | Performs local validation? | Maintained? |
---|---|---|---|---|
HTML-validate | no | yes | yes | yes |
W3C HTML Validator | yes | no | no | yes |
html-w3c-validator | yes | no | no? | yes |
html-validator | yes? | yes | no | no |
The Nu Html Checker (v.Nu) | yes | no | yes | yes |
html-validator | ? | yes | yes? | no |
HTMLHint | yes | no | yes | no |
What is âmaintainedâ here? Anything that received an update on npm within the last year.
Youâve seen my recommendations, but let me recap them here: Pretty much like youâd do for web-based HTML conformance checking, use the Nu Html Checker package in your Node or other JavaScript projects, too. If you need snippet or fragment validation, too, based on my experience filing issues and working with David Sveningsson, my next recommendation is HTML-validateâwhile itâs currently not suited for HTMLâHTML validation, it may get there, and it seems pretty well-maintained otherwise.
â§ What did I miss or mess up? Email me, or comment on the social media messages for this post (like its toot)!
About Me
Iâm Jens (long: Jens Oliver Meiert), and Iâm a web developer, manager, and author. Iâve been working as a technical lead and engineering manager for companies youâve never heard of and companies you use every day, Iâm an occasional contributor to web standards (like HTML, CSS, WCAG), and I write and review books for OâReilly and Frontend Dogma.
I love trying things, not only in web development and engineering management, but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (I value you being critical, interpreting charitably, and giving feedback.)