Don't hand-roll layout — compose primitives
A well-built component is almost no custom CSS. Push every layout decision into system.css classes in the markup; keep only shape and the type/color API in your stylesheet.
- Layout → primitives in markup:
.card(surface),.column/.row,.spread(space-between),.lcr(start/center/end),.ngridwithstyle="--cols:7"(fixed-column grid),.grid(auto-fit),.menu(anchored popover; note.centeris TEXT centering, a utility — not a box-centering primitive). Never writedisplay/flex/gridin component CSS. - Type & color → the API only:
--type(size),--bg(surfaces),--fg(ink). E.g..cal b { --type:-1; --fg:-0.9 }. - State →
data-ui-*attributes (above) +.tag[data-ui-state="on|off"]. - Shape →
aspect-ratio. This is the one geometric thing you set yourself (square day cells, square keys). Addmin-inline-size:0so 1fr grid tracks can shrink, anddisplay:grid; place-items:centerto center the glyph.
Rule of thumb: a component rarely needs more than ~10 lines of custom CSS. The month calendar is 8–9 lines total (square + number color + the two
data-ui-*outlines + the--bgin/out tints). If you're writing flexbox, you're fighting the system — reach for a primitive.