Skip to content

What it does

  • CSS Syntax by the current editor’s draft, nesting included, with a span on every rule, declaration, block and token.
  • Typed values for all 822 properties in the specs, generated from w3c/webref, with calc() and the other math functions, CSS Color 4 and 5, shorthands, custom properties and var().
  • The cascade: origins, layers, !important, style="", inheritance, revert, and media queries checked against an environment you describe.
  • Serialization back to CSS.
  • With its default features off, it’s syntax and values alone, and never compiles the HTML parser.

Add it

In Rust, add parsec-web-css (0.3.1 on crates.io); the library inside isparsec_css. Rust only for now. The Python, JavaScript and C bindings use the selector engine, not stylesheets or the cascade.

parsec-web-css 0.3.1, from its documentation
use parsec_css::{Item, Rule};

let css = "a { color: red; &:hover { color: blue } }";
let sheet = parsec_css::parse_stylesheet(css);
let Rule::Qualified(rule) = &sheet.rules[0] else { unreachable!() };
assert_eq!(parsec_css::to_css(&rule.prelude), "a ");

let contents = rule.block.clone().contents(css);
let Item::Declaration(color) = &contents.items[0] else { unreachable!() };
assert_eq!((&*color.name, color.span.start), ("color", 4));
assert!(matches!(contents.items[1], Item::Rule(_)));

That's the first example in the crate's own documentation at the v0.3.1 tag, unchanged.cargo test runs it on every change, so it compiles and passes against the release you'd install. The API reference on docs.rs has the rest, and the getting started guide goes step by step.

Checked against the standards

These counts are the conformance baseline on Parsec's main branch, read when this page was built. Each release has to match or beat them: a suite that passes fewer cases, or fails more, stops the release.

SuitePassFailSkipped
CSS tokenizer tests28700
css-parsing-tests5,0963,2700
css-parsing-tests, unicode ranges1200
web-platform-tests CSS parsing14,758135129
web-platform-tests media queries1,370014
web-platform-tests computed values11,356755355
web-platform-tests cascade1,343131199

Standards has every suite, where its data comes from, and why the failures and skips are what they are.

Where it stops

  • There are no boxes, so values that need layout, such as grid tracks as sizes or a percentage width in pixels, don’t compute. That’s most of what fails in the web-platform-tests computed-value cases.
  • Linked stylesheets aren’t fetched. It styles what you hand it.
  • css-parsing-tests was written for an older draft; the cases where the current draft changed are counted and explained rather than hidden.

The CSS page in the docs goes through the API, the limits and the conformance details in full.