Validating Static HTML and CSS With Nu HTML Checker
The Nu HTML Checker by W3C provides a convenient Docker Image which can be used to validate HTML, XML, CSS and SVG’s both online and offline.
# check public/ static website content using version 20.3.16
# check all .html files
docker run --rm -v $PWD/public:/check validator/validator:20.3.16 vnu-runtime-image/bin/vnu --skip-non-html /check
# check all .css files
docker run --rm -v $PWD/public:/check validator/validator:20.3.16 vnu-runtime-image/bin/vnu --skip-non-css /check
Introducing intentional mistakes for the tool to discover, output is on stderr and looks like:
"file:/check/css/style.min.css":2.2267-2.2267: error: CSS: “margi”: Property “margi” doesn't exist.
The command returns a non 0 exit code on error, fitting with CI type requirements:
$ echo $?
1
The --Werror
flag can be used to generate a non-zero exit status if any warning are encountered.