HTML Validator CLI
raw JSON →html-validator-cli is a command-line interface tool for validating HTML documents against the W3C's validator.w3.org/nu service. It offers a straightforward way to check HTML files, URLs, or raw HTML strings directly from the terminal. The current stable version is 7.0.1. The project demonstrates a moderate release cadence, with several patch and minor updates, and significant major version bumps (6.0.0, 7.0.0) tied to underlying `html-validator` library updates and Node.js engine requirement changes. Key differentiators include support for various output formats (JSON, HTML, text), the ability to ignore specific error messages, and options to validate local files or use a custom validator endpoint. It simplifies HTML validation workflows for developers by integrating directly into shell scripts and CI/CD pipelines without needing a browser or GUI.
Common errors
error Error: Command failed with exit code 1 Page not found ↓
--islocal flag (e.g., html-validator http://localhost:8000 --islocal). Check the URL for typos. error Error: 'html-validator' is not recognized as an internal or external command, operable program or batch file. ↓
npm i -g html-validator-cli or run it using npx html-validator ... to execute it without global installation. error The 'engines' field in package.json specifies a Node.js version (>=10.22.0) that is not satisfied by your current environment. ↓
html-validator-cli (e.g., npm install -g html-validator-cli@6 for Node.js >= 8.15.3). Warnings
breaking Node.js engine requirement increased significantly. Version 7.x now requires Node.js >= 10.22.0. Previously, v6.x required Node.js >= 8.15.3, and v5.x supported older Node.js versions. ↓
breaking Major version updates often coincide with significant changes in the underlying `html-validator` library (e.g., v6.x updated to `html-validator@4`, v7.x updated to `html-validator@5`). While the CLI aims to abstract these, subtle changes in error reporting, parsing, or supported features might occur. ↓
gotcha The `--islocal` flag is crucial for validating local development URLs without exposing them publicly. Failing to use this flag for `http://localhost:...` or similar URLs will result in 'Page not found' errors as the W3C validator cannot access them. ↓
gotcha By default, the CLI outputs 'Page is valid' or 'Page is not valid' to STDOUT and exits with code 0 or 1 respectively. Detailed error messages are suppressed unless `--verbose` is used or a specific `--format` is chosen. ↓
Install
npm install html-validator-cli yarn add html-validator-cli pnpm add html-validator-cli Quickstart
{
"name": "my-html-project",
"version": "1.0.0",
"description": "Validate HTML files in my project",
"scripts": {
"validate:url": "html-validator https://example.com --format=json",
"validate:file": "html-validator --file=./public/index.html --verbose",
"validate:data": "html-validator --data='<!DOCTYPE html><html><body><h1>Hello</h1></body></html>'"
},
"devDependencies": {
"html-validator-cli": "^7.0.0"
}
}
// To run from the command line after npm install:
// npm run validate:url
// npm run validate:file
// npm run validate:data