CSS
Attaches scoped styles to the island. Styles are automatically wrapped in a @scope rule bounded to the island host, so they apply only within the island and do not leak into child islands.
Basic usage
Plain string form
.css() also accepts a plain string, which is useful when importing styles from an external file:
Interpolations
When using the tagged template form, interpolations work as normal string concatenation:
Using the css tagged template
ilha ships a named css export that works as a passthrough tag for editor tooling. It enables LSP syntax highlighting and Prettier formatting for CSS strings without any runtime transformation. Use it to author styles outside the builder chain and pass the result in:
css(named export) is a plain passthrough tag for tooling..css()(builder method) is what actually attaches styles to the island. They are intentionally separate.
How scoping works
ilha wraps your styles in a @scope rule that constrains them to the island host and punches a hole at any nested [data-ilha] element:
This means:
- Styles apply to descendants of the island host.
- Styles do not leak into child islands nested inside.
- Selectors use low specificity and do not win unnecessary cascade wars with utility classes.
SSR output
During SSR, a <style> tag is prepended as the first child of the island's rendered HTML:
Client mount
On the client, the style element is injected once as the first child of the host. It is preserved across re-renders — morph never replaces it. During hydration, the SSR-emitted <style> node is reused and not duplicated.
Notes
- Calling
.css()more than once on the same builder chain is not supported. In dev mode a warning is logged and only the last stylesheet is used. Compose all styles into a single.css()call. .css()is compatible with.hydratable()— the style tag is included inside thedata-ilhawrapper regardless of thesnapshotoption.- Browser support for
@scopeis required. Check caniuse.com/css-cascade-scope for current coverage if you need to support older browsers.