csslib 0.14.1

  • README.md
  • Installing
  • Versions
  • 94

CSS parser library for Dart

This is a CSS parser written entirely in Dart. It can be used in the client/server/command line.

This package is installed with Pub, see: install instructions for this package.


Parsing CSS is easy!

import 'package:csslib/parser.dart';

main() {
  var stylesheet = parse(
      '.foo { color: red; left: 20px; top: 20px; width: 100px; height:200px }');

You can pass a String or list of bytes to parse.

Running Tests

Basic tests can be found in this repository:

pub run test

The full CSS test suite can be found in https://github.com/dart-lang/csslib-test-suite

cd ../csslib-test-suite


  • Deprecated package:csslib/css.dart. Use parser.dart and visitor.dart instead.


New features

  • Supports nested at-rules.
  • Supports nested HTML comments in CSS comments and vice-versa.

Breaking changes

  • The List<RuleSet> rulesets field on MediaDirective, HostDirective, and StyletDirective has been replaced by List<TreeNode> rules to allow nested at-rules in addition to rulesets.


  • Adds support for @viewport.
  • Adds support for -webkit-calc() and -moz-calc().
  • Adds support for querying media features without specifying an expression. For example: @media (transform-3d) { ... }.
  • Prevents exception being thrown for invalid dimension terms, and instead issues an error.


  • Adds support for @-moz-document.
  • Adds support for @supports.


  • Parses CSS 2.1 pseudo-elements as pseudo-elements instead of pseudo-classes.
  • Supports signed decimal numbers with no integer part.
  • Fixes parsing hexadecimal numbers when followed by an identifier.
  • Fixes parsing strings which contain unicode-range character sequences.


  • Fixes analyzer error.


  • Adds support for shadow host selectors :host() and :host-context().
  • Adds support for shadow-piercing descendant combinator >>> and its alias /deep/ for backwards compatibility.
  • Adds support for non-functional IE filter properties (i.e. filter: FlipH).
  • Fixes emitted CSS for @page directive when body includes declarations and page-margin boxes.
  • Exports Message from parser.dart so it's no longer necessary to import src/messages.dart to use the parser API.


  • Fix static warnings.


  • Fix new strong mode error.


  • Relax type of TreeNode.visit, to allow returning values from visitors.


  • Fix two checked mode bugs introduced in 0.13.0.


  • BREAKING Fix all strong mode errors and warnings. This involved adding more precise on some public APIs, which is why it may break users.


  • Fix to handle calc functions however, the expressions are treated as a LiteralTerm and not fully parsed into the AST.


  • Fix to handling of escapes in strings.


  • Allow the lastest version of logging package.


  • Top-level methods in parser.dart now take PreprocessorOptions instead of List<String>.

  • PreprocessorOptions.inputFile is now final.


  • Cleanup some ambiguous and some incorrect type signatures.


  • Improve the speed and memory efficiency of parsing.


  • Fix another test that was failing on IE10.


  • Fix a test that was failing on IE10.


  • Switch from source_maps' Span class to source_span's SourceSpan class.

1. Depend on it

Add this to your package's pubspec.yaml file:

  csslib: "^0.14.1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:csslib/css.dart';

import 'package:csslib/parser.dart';

import 'package:csslib/visitor.dart';
Version Uploaded Documentation Archive
0.14.1 Sep 21, 2017 Go to the documentation of csslib 0.14.1 Download csslib 0.14.1 archive
0.14.0 May 30, 2017 Go to the documentation of csslib 0.14.0 Download csslib 0.14.0 archive
0.13.7+1 May 22, 2017 Go to the documentation of csslib 0.13.7+1 Download csslib 0.13.7+1 archive
0.13.7 May 22, 2017 Go to the documentation of csslib 0.13.7 Download csslib 0.13.7 archive
0.13.6 May 12, 2017 Go to the documentation of csslib 0.13.6 Download csslib 0.13.6 archive
0.13.5 Apr 12, 2017 Go to the documentation of csslib 0.13.5 Download csslib 0.13.5 archive
0.13.4 Mar 7, 2017 Go to the documentation of csslib 0.13.4 Download csslib 0.13.4 archive
0.13.3+1 Jan 26, 2017 Go to the documentation of csslib 0.13.3+1 Download csslib 0.13.3+1 archive
0.13.3 Jan 26, 2017 Go to the documentation of csslib 0.13.3 Download csslib 0.13.3 archive
0.13.2+2 Nov 17, 2016 Go to the documentation of csslib 0.13.2+2 Download csslib 0.13.2+2 archive

All 99 versions...


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1


Describes how popular the package is relative to other packages. [more]
89 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]


Detected platforms: Flutter, other

Platform components identified in package: io.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use csslib.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0 <2.0.0
args >=0.12.1 <2.0.0 1.3.0
logging >=0.9.0 <0.12.0 0.11.3+1
path >=0.9.0 <2.0.0 1.5.1
source_span >=1.4.0 <2.0.0 1.4.0
Transitive dependencies
charcode 1.1.1
Dev dependencies
browser >=0.9.0 <0.11.0
test >=0.12.0 <0.13.0