tinycss2 – CSS parser and generator

tinycss2 is a low-level CSS parser and generator based on the CSS Syntax specification. It converts CSS source text into structured objects representing tokens, component values, rules and declarations. Applications can examine these objects and generate CSS strings from their contents.

The library deliberately separates CSS syntax from property-specific interpretation. It understands how CSS statements, blocks and functions are structured, but does not determine whether individual properties or values are supported by a particular CSS module. This makes tinycss2 a useful foundation for applications implementing their own CSS processing logic.

Developers can parse complete stylesheets or work with smaller pieces of CSS, such as declaration lists and component values. The resulting objects retain enough structural information for applications to inspect syntax and produce serialised output.

tinycss2 is particularly relevant to document-processing and rendering tools that require predictable handling of CSS syntax without incorporating a complete browser stylesheet engine. The parser also exposes error objects, allowing applications to examine malformed input and decide how parsing problems should be handled.

This is free and open source software.

Key Features

  • Implements low-level parsing based on the CSS Syntax specification.
  • Parses complete stylesheets and individual CSS rule lists.
  • Supports declaration-list and component-value parsing.
  • Recognises nested functions and blocks.
  • Provides structured tokens for identifiers, strings, dimensions and other CSS syntax.
  • Exposes parsing errors for malformed input.
  • Supports parsing CSS found inside HTML style attributes.
  • Preserves comments and whitespace when requested.
  • Serialises parsed CSS objects back into stylesheet text.

Website: github.com/Kozea/tinycss2
Support:
Developer: Simon Sapin and contributors
License: BSD 3-Clause ‘New’ or ‘Revised’ License

tinycss2 is written in Python. Learn Python 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