# CSS ## h-css: hyperscript-style CSS generation h-css is a string-returning function that constructs CSS from declarative options objects. Same pattern as h-xml and h-html: call `$()` with named parameters, get a string back. ```ts $({ rule: '.card', decls: { display: 'flex', gap: '1rem', }, },); // '.card{display:flex;gap:1rem}' ``` ### Why not template literals Template literals in CSS-in-JS (Lit's `css`, styled-components, Emotion) treat CSS as opaque strings. Editors see them as plain text: no property name autocomplete, no value validation, no type checking. Composition requires string interpolation, which breaks structure and makes refactoring fragile. h-css uses object keys for property names and object values for property values. TypeScript types the keys via `csstype`'s `PropertiesHyphen` (auto-generated from MDN browser compatibility data), giving editor intellisense for every standard CSS property in kebab-case and value autocomplete for each property. Custom properties (`--*`) are also accepted via a template literal index signature. ### Why not external CSS files External CSS files (CSS Modules, vanilla-extract, Tailwind, UnoCSS) generate stylesheets that attach to the document's global scope. Shadow DOM encapsulation prevents these global stylesheets from reaching shadow roots. Injecting external CSS into each shadow root requires either duplicating the file content or using `adoptedStyleSheets` with constructable stylesheets. Both add machinery that h-css eliminates by generating CSS strings directly where they're needed. ### Why not runtime CSS-in-JS Runtime CSS-in-JS libraries (Emotion, styled-components, Goober) inject styles into `