Click on the question to see the answer.

What is NSAC?

NSAC is a low-level event API for CSS parsing, an evolution of W3C's SAC. NSAC 2.x is not backwards-compatible with SAC, but similar enough that migrating from it should be relatively easy (if you require compatibility with SAC, you may still use version 1 of NSAC, shipped with css4j 1.x).

However, most developers use the higher-level CSS Object Model and do not need to care about NSAC except when handling var() fallback values or the var()-related CSSLexicalValue.

Are W3C's CSSValue and CSSPrimitiveValue interfaces supported?

That API was deprecated by W3C but version 1.0 does implement them. Version 2 and later uses those names but the actual interfaces are different and not backwards-compatible.

How do I access the document style sheets?

The document style sheets are a collection of style sheets associated with the document. W3C's DOM Level 2 Style standard provides the DocumentStyle interface for that, see also Extensions to the Document Interface in the more modern CSSOM. That is, just use document.getStyleSheets() to get the list of style sheets.

Can I get the merged style sheet that applies to the document?

The document.getStyleSheet() method does that. Although you can add style rules to it, you may consider using overriden styles or the user-defined style sheet (neither are included in the sheet returned by that method) instead.

How can I remove all the rules in a style sheet?

Use sheet.getCssRules().clear().

What is the difference between CSSParser and CSSOMParser? [2.0 or higher]

When parsing media queries, the CSSOMParser class has an object-model internal factory that directly produces CSSOM-enabled media queries, while CSSParser has a -less useful- factory based on NSAC lexical units.

If you want to parse media queries you probably want to use CSSOMParser, otherwise CSSParser should be adequate.

Does css4j depend on dom4j?

The core module does not, but css4j-dom4j is one of the available DOM back-ends (and that one does depend on dom4j).

Does css4j-dom4j work with dom4j 1.x or 2.x?

Although the provided Maven build requires dom4j 2.x, the resulting jar file can be used in runtime with 1.x too. Css4j-dom4j makes no use of the methods that dom4j implements in 2.x but not in 1.6, so it is safe to use with 1.6. Recent versions aren't tested with 1.6 however.

Using the dom4j back-end prior to version 3.1, I find that dom4j does not support using the document's uri to retrieve relative urls. How can I work around?

You can manually set the base url, doing something like:

if (document.getBaseURL() == null) {

From version 3.1 onwards, the css4j-dom4j module does implement and support Document.setDocumentURI().

Does the DOM4J back-end make use of the DOM wrapper, internally?

No, they are independent back-ends.

How do I set up my document for computing paged-media styles?

Use document.setTargetMedium("print") and then compute the styles. setTargetMedium rebuilds the style cascade for the new medium.

I have set up a style database, but the library complains about missing it.

Be sure to call document.setTargetMedium("medium"), where the medium must be the same for which the style database was set.

The style database is an abstraction that supplies initial values for properties that are User Agent-dependent. Why not just set them at the UA style sheet?

The user agent sheet depends on the document type and is not always loaded, while the style database is document-independent (but medium-specific).

Are the minification methods recommended for production use?

This library's support for minification (getMinifiedCssText() and related methods) is not intended as a general-purpose minification solution, but could be useful as part of a wider CSS toolchain, perhaps with a specialized minifier at its end.

If you decide to use the minification methods in 1.x be sure to use this library's internal parser, and not the other SAC parsers. And if you use any kind of Internet Explorer hack, please use a sheet factory with the proper NSAC parser flags set. Some IE hacks are supported, but others may give unexpected results so you should be very careful about that.

Are this project's artifacts available on Maven Central?

No, as this project does not accept Maven Central's terms of use.