Theming
@codeui/styles v0.3.0
Light and dark scopes, token overrides, density, and cascade layers.
Light and dark
Set data-cui-theme="light" or data-cui-theme="dark" on any element. The theme applies to its subtree, so one page can hold both.
<div class="cui-stack" data-direction="row" data-gap="3" data-wrap="true"> <div data-cui-theme="light" class="cui-stack" data-gap="3" style="flex: 1; min-width: 220px; padding: 20px; border-radius: 12px; background: var(--cui-surface-panel); color: var(--cui-text-default)"> <span class="cui-text" data-weight="medium">Light scope</span> <div class="cui-stack" data-direction="row" data-gap="2"> <button type="button" class="cui-button" data-cui="button" data-variant="primary">Export</button> <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy</button> </div> </div> <div data-cui-theme="dark" class="cui-stack" data-gap="3" style="flex: 1; min-width: 220px; padding: 20px; border-radius: 12px; background: var(--cui-surface-panel); color: var(--cui-text-default)"> <span class="cui-text" data-weight="medium">Dark scope</span> <div class="cui-stack" data-direction="row" data-gap="2"> <button type="button" class="cui-button" data-cui="button" data-variant="primary">Export</button> <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy</button> </div> </div></div>With no attribute on the root, the page follows the system prefers-color-scheme. Set the attribute on <html> to force a theme, and switch it at run time to follow a user setting.
Content outside the theme scope does not get its tokens. If you move overlays to the end of body, keep a data-cui-theme element around them.
Tokens
Components read semantic --cui-* custom properties. Override them on a theme scope or on any ancestor of the components that should change.
[data-cui-theme="dark"] {
--cui-action-brand-base: #4f8cff;
--cui-radius-scale: 1.2;
}<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="primary">Default brand</button> <div style="--cui-action-brand-base: #7c3aed; --cui-action-brand-hover: #6d28d9; --cui-action-brand-active: #5b21b6; --cui-radius-scale: 2"> <button type="button" class="cui-button" data-cui="button" data-variant="primary">Custom brand</button> </div></div>The Inkstone colour page lists the semantic roles. Each component page in the kit docs lists the tokens it reads under "Theming hooks".
Density
data-cui-density sets control heights for a subtree: compact, comfortable (the default), or touch. A coarse pointer selects touch automatically. Font sizes stay the same.
<div class="cui-stack" data-direction="row" data-gap="6" data-align="end" data-wrap="true" data-justify="center"> <div data-cui-density="compact" class="cui-stack" data-gap="2" data-align="center"> <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy snippet</button> <span class="cui-text" data-size="xs" data-tone="muted">compact</span> </div> <div data-cui-density="comfortable" class="cui-stack" data-gap="2" data-align="center"> <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy snippet</button> <span class="cui-text" data-size="xs" data-tone="muted">comfortable</span> </div> <div data-cui-density="touch" class="cui-stack" data-gap="2" data-align="center"> <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy snippet</button> <span class="cui-text" data-size="xs" data-tone="muted">touch</span> </div></div>Cascade layers
All component rules live in the cui layer, in the order cui.base, cui.components, cui.overrides. Every CSS entry declares that order first, so entries can load in any order.
Unlayered CSS beats layered CSS. Your own rules override the library without extra specificity:
/* Wins over the library, even with a lower specificity. */
.checkout-button {
border-radius: 999px;
}If your app uses its own layers, declare cui before them:
@layer cui, app;