Overview#
Implement CSS Custom Properties (CSS Variables) per the CSS Custom Properties for Cascading Variables Module Level 1 specification.
Requirements#
Parsing#
- Parse custom property declarations:
--property-name: value - Parse
var()function references:var(--property-name)andvar(--property-name, fallback) - Custom property names are case-sensitive and must start with
-- - Values can contain any valid CSS tokens (preserved as-is until substitution)
Cascade & Inheritance#
- Custom properties participate in the cascade (specificity, source order)
- Custom properties are inherited by default
- Support
initialkeyword to reset a custom property - Resolve
var()references during computed style resolution
Substitution#
- Replace
var()references with the custom property's computed value - Support fallback values:
var(--missing, red)resolves toredif--missingis not defined - Nested
var()in fallback:var(--a, var(--b, blue)) - Detect and handle cyclic references (treat as invalid)
Integration#
- Integrate with existing CSS parser in
crates/css/ - Integrate with style resolution in
crates/style/
Acceptance Criteria#
-
--custom: valuedeclarations parse correctly -
var(--custom)resolves to the declared value -
var(--missing, fallback)returns the fallback - Custom properties inherit through the DOM tree
- Cyclic references are detected and handled gracefully
- All existing tests continue to pass
- New unit tests cover parsing, inheritance, substitution, and cycles