postcss-selector-parser is a library for parsing and manipulating CSS selectors. It converts selector strings into an abstract syntax tree (AST), allowing developers to inspect, modify, and reconstruct selectors without manually processing their individual characters. The library is commonly used in stylesheet transformation tools, including applications built around the PostCSS ecosystem.
CSS selectors can contain complex combinations of element names, classes, IDs, attributes, pseudo-classes, and combinators. Working with these structures as plain text can be difficult, particularly when modifying selectors while preserving their original meaning. postcss-selector-parser provides an object-based interface that exposes these components individually, making it possible to perform targeted transformations and generate updated selector strings.
This is free and open source software.
Key Features
- Parse CSS selector strings into an editable abstract syntax tree.
- Traverse selector nodes using visitor methods for different selector types.
- Inspect and modify class, ID, element, attribute, and pseudo-class selectors.
- Support for combinators, nested selectors, and CSS nesting syntax.
- Construct selector nodes programmatically and insert them into existing trees.
- Remove, replace, and rearrange selector components.
- Serialize modified selector trees back into CSS strings.
- Preserve original whitespace and comments when processing selectors.
- Optional whitespace normalization for producing compact selector strings.
- Automatic escaping of characters that are invalid in CSS identifiers.
- Synchronous and asynchronous selector-processing interfaces.
- Configurable input-length and nesting-depth limits for processing untrusted selectors.
- Integration with PostCSS without requiring PostCSS as a dependency.
Website: github.com/postcss/postcss-selector-parser
Support:
Developer: PostCSS contributors
License: MIT License
postcss-selector-parser is written in JavaScript. Learn JavaScript 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.