JSCSSP a CSS parser in JavaScript

JSCSSP is a CSS parser written in cross-browser JavaScript. It parses a string containing CSS styles and outputs a CSS Object Model (warning: not the CSS Object Model). It can preserve some comments, at-rules and style rules that your browser does not recognize and trashes, and even whitespaces if you absolutely need to preserve indentation and blank lines.

NEW JSCSSP now has support for CSS Media Queries

JSCSSP is NOT based on regular expressions for parsing, making it robust and easily extensible.

It's very simple to use and manipulate, and can be used to write a CSS validator, filters or even CSS extensions for a given browser. Here is the whole code for the interactive demo below:

var source = document.getElementById("source"); var ss = source.value; var parser = new CSSParser(); var sheet = parser.parse(ss, false, true); var serialization = document.getElementById("serialization"); if (sheet) serialization.innerHTML = sheet.cssText(); else serialization.innerHTML = "";