WestNIC provides reliable web hosting services
100 Best Free Web Space offers high quality free web hosting reviews
Fastwebhost offers cheap web hosting & reseller hosting services
The W3C CSS validation service is delivered as a Java servlet but can also be installed as a desktop application integrated with your favourite CSS editor. This article explains how to set up the W3C CSS checker so you can validate your CSS with a few clicks.
The W3C validator is free open source software, but the documentation for the system is minimal, incomplete and written for Java developers. This article is written for CSS developers that are Java novices. If you find this article is unclear or assumes too much about what you know, use the feedback form below to suggest improvements.
css-validator.jar file.
jigsaw.jar file from the directory Jigsaw/classes.
velocity-1.6.2.jar
xercesImpl.jar file from the main project directory.
tagsoup-1.2.jar.
commons-collections-3.2.1.jar.
commons-lang-2.4.jar.
For convenience save the 7 JAR files in a single directory with short names. The examples below use D:\java\css, adjust your own directory references as necessary.
You probably have the Java Runtime Environment installed as a Web browser plugin to run Java applets. To check, open a command window and call the java -version command. On Windows, click on the Start button and choose Run.
Type cmd and press Enter or click OK to open a command console. Then type java -version and press Enter. You will most likely see a Java version statement like the one below.
C:\>java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition
Java HotSpot(TM) Client VM (build 1.5.0_13-b05)
If you get an error message when you check the Java version, that the command is not recognised, download and install the JRE from the Java SE Downloads page. When installation is complete Java should be added to the system search path, repeat the version check and you should see a confirmation message like the one above.
The configuration of the CSS validator requires all the supporting Java Archive file references to be passed in the Java classpath argument, which makes for a very long command line. To simplify integration with your chosen CSS editor, create a shell script to encapsulate all the command line arguments and use a numbered parameter argument to pass the CSS source reference to the script.
The -classpath argument in the examples below is split over several lines for clarity, your working version should be one continuous line with no spaces. The Java class name org.w3c.css.css.CssValidator should have a space before and after.
ValidateCSS.bat
The Windows classpath is separated by semi-colons. The numbered parameter argument is prefixed by a percent symbol. Note the file references in the classpath argument use forward slashes. Save as D:\java\css\ValidateCSS.bat to follow this example.
ECHO OFF
CLS
java -classpath D:/java/css/css-validator.jar;
D:/java/css/jigsaw.jar;
D:/java/css/velocity-1.6.2.jar;
D:/java/css/tagsoup-1.2.jar;
D:/java/css/commons-lang-2.4.jar;
D:/java/css/commons-collections-3.2.1.jar;
D:/java/css/xercesImpl.jar
org.w3c.css.css.CssValidator %1
To test the Windows batch script, open a command window as above, type the path to the script followed by the URL of an HTML page to check. Press Enter to validate. Note the directory path on Windows uses back slashes, \.
C:\> D:\java\css\ValidateCSS http://www.w3c.org/
If your validator script test is successful, you should see output that starts as follows then lists the style sheet content.
{output=text, medium=all, warning=2, profile=css21, lang=en}
W3C CSS Validator results for http://www.w3.org/
Congratulations! No Error Found.
This document validates as CSS level 2.1 !
The most likely errors will be incorrect or incomplete classpath references for the 7 JAR files, so check and correct as necessary. This test requires an Internet connection.
The W3C validator requires a file:/ prefix to process CSS files, so save a modified version of your shell script to handle files, as below. The file prefix could be passed to the script rather than embedded in it, but this arrangement will make integration with your CSS editor easier at the next step.
ValidateCSSFile.bat
ECHO OFF
CLS
java -classpath D:/java/css/css-validator.jar;
D:/java/css/jigsaw.jar;
D:/java/css/velocity-1.6.2.jar;
D:/java/css/tagsoup-1.2.jar;
D:/java/css/commons-lang-2.4.jar;
D:/java/css/commons-collections-3.2.1.jar;
D:/java/css/xercesImpl.jar
org.w3c.css.css.CssValidator file:/%1
Test the script as before, but pass a CSS file name enclosed in quotes instead of a URL. The quotes allow for spaces in the file path. The Windows file path uses back slashes, \ to separate directories.
C:\>D:\java\css\ValidateCSSFile "D:\java\css\Print.css"
The shell scripts above will simplify the process of running the CSS validator from a command console, but any good text or CSS editor should be able to run the validator on the current file. The examples below show how to integrate the W3C CSS validator with TextPad, EditPlus and UltraEdit for Windows and indicate the equivalent settings in your preferred CSS editor.
The EditPlus text editor is available at http://www.editplus.com/.
ValidateCSSFile.bat program created above.
$(FilePath) parameter for the current file.
This validation option can be accessed via the Tools menu and will have a keyboard shortcut assigned.
The TextPad text editor is available at http://www.textpad.com/.
ValidateCSSFile.bat script created above.
$File parameter to specify the current file.
TextPad applies output capture settings by default to list the validation results in the editor window. The new validation option can be accessed via The Tools menu and will have a keyboard shortcut assigned.
The UltraEdit text editor is available at http://www.ultraedit.com/.
ValidateCSSFile.bat script created above.
ValidateCSSFile.bat script and add the %F parameter to specify the current file.
%P parameter to specify the current directory.
This validation option can be accessed via the Advanced menu, and will have a keyboard shortcut assigned.
The W3C CSS validator will accept a number of additional command arguments to configure how it processes style sheets and formats the results. The general scheme is to follow the validator class name org.w3c.css.css.CssValidator with one or more option commands before the final CSS source reference.
... org.w3c.css.css.CssValidator -profile css3 file:/%1
... org.w3c.css.css.CssValidator -medium print file:/%1
... org.w3c.css.css.CssValidator -warning 0 file:/%1
Multiple configuration commands can inserted in your shell script, but always place the URL or file reference last in the list.
-profile PROFILE or --profile=PROFILE
PROFILE, one of:
css1 CSS level 1
css2 CSS level 2
css21 CSS level 2 revision 1 default
css3 CSS level 3
svg SVG
svgbasic SVG Basic
svgtiny SVG Tiny
atsc-tv ATSC TV
mobile CSS Mobile Profile
tv CSS TV Profile
-medium MEDIUM, --medium=MEDIUM
MEDIUM, one of:
all default
aural
braille
embossed
handheld
print
projection
screen
tty
tv
presentation
-warning WARN, --warning=WARN
-1 no warnings
0
1
2 default, all warnings
-lang LANG, --lang=LANG
de German
en English, default
es Spanish
fr French
it Italian
ja Japanese
ko Korean
nl Dutch
pl Polish
zh-cn Chinese
URL
URL can either represent a remote Web resource with a standard http:// prefix, or a local file path with file:/ prefix, e.g. file:/D:/java/css/CSPrint.css.
-output OUTPUT, --output=OUTPUT
OUTPUT format, one of:
text (default)
xhtml XHTML
html HTML (same format as XHTML)
soap12 Simple Object Access Protocol
-p, --printCSS
Find out how to add a fast and powerful markup validator to your development environment. Validate your markup with NSGMLS explains how to configure this free tool and how to integrate it with three popular text editors.
JTidy is a Java implementation of Dave Raggett's HTML Tidy, which cleans up tag soup to produce well formed XHTML for further processing. Read our practical JTidy development notes for important integration details from the Code Style site log.