Skip to content

Instantly share code, notes, and snippets.

@alexrutar
Last active August 20, 2023 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrutar/d226691e6edb1d64b64a3220bb9ec521 to your computer and use it in GitHub Desktop.
Save alexrutar/d226691e6edb1d64b64a3220bb9ec521 to your computer and use it in GitHub Desktop.
Validate HTML using the W3C API from the command line.

We can use httpie to make requests to the W3C validator. For example, to test the file index.html, run

https "https://validator.w3.org/nu/?out=gnu" @index.html "Content-Type: text/html; charset=utf-8" --print 'b'

and any errors or warnings will be printed to STDOUT. You can also get the error format in JSON by using the out=json syntax.

Another option which can be done locally is to use the python html5validator. For example, if all your files are in a directory called html, calling

html5validator --root html/ --also-check-css --show-warnings

will check all .html files as well ass .css files in that directory, and print warnings as well as errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment