HTML Conformance: A Comparison of 6.5 npm Validator Packages (With 1.5 Recommendations)
Published on December 17, 2024, filed under Development (RSS feed for all categories).
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 frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, 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. (Please be critical, interpret charitably, and give feedback.)
Read More
Maybe of interest to you, too:
- Previous: When We Need Systems, Processes, and Conventions
- More under Development
- More from 2024
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.info—and The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.