CSSTree – CSS parser, generator, walker and lexer

CSSTree is a collection of tools for parsing, analysing and generating CSS. It combines a detailed CSS parser with facilities for traversing syntax trees, generating stylesheets and matching CSS syntax against predefined grammars.

The parser converts CSS into an abstract syntax tree whose nodes represent individual logical components. Applications can inspect and modify these structures to perform stylesheet analysis or source-to-source transformations.

CSSTree is designed to follow CSS specifications while recovering from malformed input. Instead of discarding every unrecognised construct, it can retain problematic content in raw nodes for further processing. The library’s lexer provides syntax-matching facilities using definitions derived from web standards and browser implementations. This is particularly useful when checking property values or at-rule syntax.

The level of parsing detail can be adjusted according to the application’s needs. For example, a tool that does not require detailed selector analysis can reduce the amount of parsing performed on selectors. These capabilities make CSSTree suitable for CSS validation, minification, code analysis and other tasks requiring structured access to stylesheet content.

This is free and open source software.

Key Features

  • Parses CSS into a detailed abstract syntax tree.
  • Offers configurable parsing granularity.
  • Provides error-tolerant parsing with raw-node preservation.
  • Includes syntax-tree walking and traversal utilities.
  • Supports modification and generation of CSS syntax trees.
  • Provides grammar-based matching for recognised CSS constructs.
  • Uses MDN data and additional definitions for CSS syntax validation.
  • Supports analysis of declarations, selectors, values and at-rules.
  • Designed for efficient stylesheet parsing and low memory overhead.

Website: github.com/csstree/csstree
Support:
Developer: Roman Dvornov
License: MIT License

CSSTree is written in JavaScript. Learn JavaScript with our recommended free books and free tutorials.


Related Software

CSS Parsers
PostCSSTransform styles with JavaScript plugins
Lightning CSSParser, transformer, bundler, and minifier
ReworkPlugin framework for CSS preprocessing
PHP CSS ParserPHP library for reading CSS
MenschNon-validating CSS parser
CSSTreeTool set for CSS
StylisLightweight CSS preprocessor
tinycss2CSS parser and generator
ParseGo library offering lexers, parsers, and parsing utilities
LibCSSCSS parser and selection engine
Ruby CSS ParserLoad, parse and cascade CSS rule sets
ParserLibCSS3 SAX-inspired parser
css-parserFork of the cssutils project
ph-cssParse, represent, modify, and write CSS stylesheets
StylecowModern CSS to all browsers
Gonzales PECSS parser which plays nicely with preprocessors
CSSOMCSS parser written in pure JavaScript

Read our verdict in the software roundup.


Best Free and Open Source Software LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.

We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more.

Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion.

Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted