tree-sitter-css – CSS grammar for Tree-sitter

tree-sitter-css is a CSS grammar for the Tree-sitter parsing system. It defines the syntactic structure of CSS, allowing Tree-sitter to construct syntax trees that can be inspected by text editors, development environments, and source code analysis tools. The grammar provides the rules needed to recognise CSS selectors, declarations, property values, and stylesheet constructs.

Tree-sitter is designed for applications that need to analyse source code while it is being edited. Its incremental parsing approach allows syntax trees to be updated as the underlying document changes, rather than requiring an entire file to be parsed from scratch after every modification. tree-sitter-css supplies the CSS-specific grammar used by this system, providing a foundation for syntax-aware editing, highlighting, navigation, and code analysis.

This is free and open source software.

Key Features

  • Grammar definitions for parsing CSS stylesheets into structured syntax trees.
  • Recognition of CSS selectors, declarations, property names, and values.
  • Support for class, ID, attribute, pseudo-class, and pseudo-element selectors.
  • Parsing of descendant, child, sibling, and adjacent sibling combinators.
  • Support for @import, @media, @charset, and @namespace rules.
  • Recognition of @keyframes, @supports, and @scope constructs.
  • Parsing of nested CSS rules and declaration blocks.
  • Recognition of CSS functions, numeric values, units, colours, and strings.
  • Integration with Tree-sitter’s incremental parsing and error recovery.
  • Highlight queries identifying selectors, properties, values, operators, and keywords.
  • Syntax tree support for editor features such as code navigation and structural analysis.
  • Language bindings for integrating the grammar into applications using Tree-sitter.

Website: github.com/tree-sitter/tree-sitter-css
Support:
Developer: Max Brunsfeld, Amaan Qureshi and contributors
License: MIT License

tree-sitter-css 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