v133 ยท css
CSS advanced attr() function
Implement the augmentation to attr() specified in CSS Level 5, which allows types besides <string> and usage in all CSS properties (besides pseudo-element 'content').
concepts
-
Typed attr()
attr() learns typed values + fallbacks. Cascade-friendly way to thread element-level data into property values.
-
Data-driven chart
A bar chart whose width and colour come straight from
data-pctanddata-colorattributes — no JS recolour, no CSS custom-property bridge. The 14-year-old request use case, made real. -
Type explorer
Drive one card through four typed attributes —
<color>,<length>,<angle>,<percentage>. Corrupt any one and watch its own fallback kick in. -
Palette wall
120 swatches, one CSS rule. Each swatch paints itself from
data-hexwith a readable contrasting label colour — mark-up reduces to pure data. -
Progress Bars
Progress bars styled entirely from
data-valueattributes viaattr(data-value type(<number>), 0)incalc()โ no inline style, no JS, no CSS variable bridge. Includes ratio bars using two attributes and a live slider editor. -
Product Card
A product card where price counter, star rating, stock bar, and out-of-stock state are all driven by
data-price,data-rating,data-stock,data-discountattributes. Zero inline styles; CSS reads each attribute via typedattr().
why it shipped
This is a highly requested feature, with 123 stars at crbug.com/246571. We also want to keep it considered in the CR period by adding the first implementation.