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 | |
|---|---|
| PostCSS | Transform styles with JavaScript plugins |
| Lightning CSS | Parser, transformer, bundler, and minifier |
| Rework | Plugin framework for CSS preprocessing |
| PHP CSS Parser | PHP library for reading CSS |
| Mensch | Non-validating CSS parser |
| CSSTree | Tool set for CSS |
| Stylis | Lightweight CSS preprocessor |
| tinycss2 | CSS parser and generator |
| Parse | Go library offering lexers, parsers, and parsing utilities |
| LibCSS | CSS parser and selection engine |
| Ruby CSS Parser | Load, parse and cascade CSS rule sets |
| ParserLib | CSS3 SAX-inspired parser |
| css-parser | Fork of the cssutils project |
| ph-css | Parse, represent, modify, and write CSS stylesheets |
| Stylecow | Modern CSS to all browsers |
| Gonzales PE | CSS parser which plays nicely with preprocessors |
| CSSOM | CSS parser written in pure JavaScript |
Read our verdict in the software roundup.
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. |


Please read our Comment Policy before commenting.