CSS
From a stylesheet’s first token to an element’s computed values: the syntax, the values of every property the specs define, and the cascade that decides which one wins.
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 andvar(). - 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.
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.
| Suite | Pass | Fail | Skipped |
|---|---|---|---|
| CSS tokenizer tests | 287 | 0 | 0 |
| css-parsing-tests | 5,096 | 3,270 | 0 |
| css-parsing-tests, unicode ranges | 12 | 0 | 0 |
| web-platform-tests CSS parsing | 14,758 | 135 | 129 |
| web-platform-tests media queries | 1,370 | 0 | 14 |
| web-platform-tests computed values | 11,356 | 755 | 355 |
| web-platform-tests cascade | 1,343 | 131 | 199 |
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.