CSS Preprocessor tool and library

CSS Preprocessor Logocsspp

CSS Preprocessor (csspp) is a scripting language that transforms advanced (extended) CSS code into a script that browsers can read.

The input to csspp can be the same as standard CSS, or it can use extensions as described below such as using basic math, embedding rules in other rules (cascading by nesting) and many other things.

The project offers a C++ library that can readily be used in your own C++ project and a command line tool.

Status: version 1.0.10 released.

I have go a complete csspp command line to compile your CSS or SCSS files to one of 4 available formats.


The lexer reads UTF-8 files and transform them in token.


The parser makes sure that the basic CSS 3 syntax is respected (that you have ':' and '{}' in the right place.)


The compiler transforms the tree in a set of @-keywords and rules with declarations. This includes quite a few validations already.

The compiler includes support for C/C++ like expressions. It supports logical operators (&&, ||, and ^^), relational operators (<, >, <=, >=, =, and !=), additive operators (+ and -), multiplicative operators (*, /, and %), power operators (**), unary expressions (- and +), many functions.

What is still missing is a validation process of all the declarations. There are two such validations: (a) in a specific rule can only have a certain number of declarations, for example content: is not available for a table field; and (b) each declaration only accept a certain number of data entry that have to follow a specific syntactical definition from the CSS 3 language. For example, the color: declaration expects one parameter which has to be a color or one of the few identifiers that can be used in that declaration (such as inherit.) This will be done using external files as we already have to validate various entries such as identifiers used after a colon (:) in a list of selectors. These identifiers are limited and thus we can very easily check them and make sure they are valid.


The assembler outputs a tree the compiler just worked on in one of 4 different formats (compressed, tidy, expanded, beautified.)


A CSS Preprocessor tarball can be downloaded as a tarball from SourceForge.net. You can also find the source in the snapcpp project, again on SourceForge.net:


Note that to compile the source you also need the snapCMakeModules, controlled_vars, and advgetopt modules. All of those are part of the tarball distribution.


References of the csspp C++ library and command line are available online on this CSS Preprocessor website.


The scripting language supported by csspp is based on the language developed by SASS. This language allows you to include variables and nested rules making it easier to develop complex rules.

$error_color: red;
div.warning {
  width: 75%;
  a {
    color: $error_color;

This definition results in the following output:

div.warning {
  width: 75%;
div.warning a {
  color: red;

The variable was replaced by its content, and the nested rule (a) was output unnested.

These are certainly the main two features of this scripting language. There are many other features described in the documentation.


csspp is partially based on SASS. Most of the extensions of SASS will be implemented in csspp. However, the main reason for me to write csspp is to validate all the CSS rules before sending them to a browser and not so much having support for automatically generated rules and other such features of SASS.



  • Further updates to support the yet new advgetopt.
  • Updated the dev/pack to work with the newest version.


  • Fixed the advgetopt exception names.


  • Added libboost-dev as a dependency.


  • Added the libutf8 as a dependency.


  • Fixed the fallthrough statements for C++17.
  • Added the system advgetopt command line options.


  • Cleaned up the doxygen configuration file.
  • Added snapdev as a dependency.


  • Update to match the new advgetopt.


  • Removed the definition of the CSSPP version from the selectors.scss.


  • Made code compatible with -Weffc++.


  • Added a catch to properly exit on that exception.


  • Removed the warning when finding a #id after other selector (it's actually not completely impossible that it would be useful because classes can change over time).


  • Fixed the DIVIDE for calc() so it works.


  • Added a try/catch in a destructor.


  • Added"rem" to the test to make sure it works.


  • Added support for @keyframes.
  • Added a new node type (FRAME).
  • Added support for specialized pseudo names.
  • Converted the dev/version script to retrieve the version from the changelog.


  • Added a fix to the output of declaration with multiple argument lists. Each argument list has to be separated by a comma.


  • Added a few catch() to main() of the csspp tool. (Coverity)
  • Fixed a bug (4 instances) with the '&' operator. Version 1.0.8 had one fix.


  • Fixed a potential buffer overflow in lexer::ungetc().
  • Fixed a test in a while(), missing parenthesis, in a test.
  • Compiler created using 'this' instead of 'true' as parameter.
  • Fixed the name of a #define of a header file.


  • Keep identifier case since it can be important for classes and tags.


  • Implemented the @return so external functions work as expected.
  • Bug fixes and documentation updates.


  • Tests all the expressions, fixed many bugs in that area.
  • Quite a few other bug fixes.


  • Tests and corrections to the implementation of the power operator.


  • Tests and corrections to the implementation of the multiplicative operator.

1.0.2, 1.0.1

  • Various changes in link with bugs I have found while implementing the final tests (outside of the expression tests).

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly