Validating HTML and CSS with curl

Sun, 16 Mar 2014 00:00:00 GMT

The World Wide Web Consortium (W3C) provide automatic validation tools for HTML and CSS. Sometimes it's handy to be able to validate a web page or style cheet from the command line. Here is a way to do it with curl:

HTML

This is how I validate my HTML files with curl:

$ curl --form "uploaded_file=@file.html;type=text/html" --silent \
               --show-error https://validator.w3.org/check | grep -q '[Valid]'

CSS

and CSS:

$ curl --form "file=@file.css;type=text/css" --silent --show-error \
               https://jigsaw.w3.org/css-validator/validator | \
               grep -q 'Congratulations! No Error Found.'