How to Validate CSS on Internal Web Pages

How can I validate CSS on internal web pages?

You can invoke the W3C validator from the command line:

Command-Line use

Any computer with Java installed can
also run the validator from the
terminal/console as a commandline
tool. Download the css-validator.jar
jar archive (or build it with ant jar)
and run it as :

java -jar css-validator.jar http://www.w3.org/

Note : the css-validator.jar file must
be located at the exact same level as
the lib/ folder to work properly.

Update: To get it to work, I checked out the full distribution from CVS and ran ant using the included build.xml. It downloaded all dependencies except for servlet.jar. To deal with that, I downloaded the binary distribution of Tomcat 6 and extracted it. Then, I edited the build.xml for css-validator to reflect the location of servlet.lib:

<property name="servlet.lib" 
value="E:/Downloads/apache-tomcat-6.0.20/lib/servlet-api.jar"/>

Then ran ant again. This produced the css-validator.jar file in the top level of the directory checked out from CVS with the lib subdirectory containing the other jars it depends on. Then, I was able to run the validator successfully:

C:\Temp\validator\2002\css-validator> java -jar css-validator.jar http://www.unur.com/

W3C css-validator.jar: Where do I find documentation about local usage (parameters, etc.)?

I didn't find a lot of information about this, but at least here are some configuration parameters:

http://jigsaw.w3.org/css-validator/manual.html

How to prevent W3C Validator from parsing internal CSS?

When checking a HTML5 document with https://validator.w3.org/, you’ll get redirected to https://validator.w3.org/nu/, so the latter is likely the validator you are using.

WHATWG’s HTML spec introduced this requirement for the content of a style element:

The child text content of a style element must be that of a conformant style sheet.

This means: If you want to have a valid WHATWG-HTML document, your CSS in the style element needs to be valid, too. This wasn’t the case previously.

However, W3C’s HTML spec doesn’t have this requirement for the style element, as of 2017-12-26. Unless they add that requirement, too, W3C-HTML documents would still be valid even if they contain invalid CSS in style elements. Then maybe the validator instance hosted by the W3C will disable this CSS checking feature.

(Some days ago, a user asked for a switch in the validator to disable checking the CSS. The maintainer "will look into this".)



Related Topics



Leave a reply



Submit