Skip to Content
CodeUI

Theming

@codeui/solid v0.3.0

Every kit value is a --cui-* CSS custom property. Change them with plain CSS, per app, per mode or per subtree.

The CodeImage look is the default. Every color, radius, space, shadow and motion value is a --cui-* custom property, and every component reads only those properties. You change the theme with plain CSS. Your own stylesheets need no vanilla-extract.

theming/modes.tsx
import { Button, Switch, TextField } from "@codeui/solid";
import { For } from "solid-js";

const scope = {
	display: "flex",
	"flex-direction": "column",
	gap: "var(--cui-space-3)",
	padding: "var(--cui-space-4)",
	"border-radius": "var(--cui-radius-card)",
	background: "var(--cui-surface-canvas)",
	color: "var(--cui-text-default)",
	"min-width": "240px",
} as const;

export default function ThemingModes() {
	return (
		<For each={["dark", "light"] as const}>
			{mode => (
				<div data-cui-theme={mode} style={scope}>
					<TextField size="sm" label="Snippet name" placeholder="Untitled" />
					<Switch label="Show line numbers" defaultChecked />
					<Button variant="primary" size="sm">
						Export PNG
					</Button>
				</div>
			)}
		</For>
	);
}

Both groups render the same components. The first sets data-cui-theme="dark", the second data-cui-theme="light".

Pick dark, light or system

data-cui-theme is the only theme attribute. It takes two values.

AttributeResult
data-cui-theme="dark"Dark values. color-scheme: dark.
data-cui-theme="light"Light values. color-scheme: light.
No attributeSystem. Dark values under prefers-color-scheme: dark, light values otherwise.
  • Set the attribute on <html> to theme the whole page.
  • Set it on any element to theme that subtree. Each scope sets again every token that has a dark and a light value, so a light scope inside a dark page works.
  • To follow the system setting, remove the attribute. There is no system value.

The kit ships no theme provider. If your app stores a dark, light or system preference, write the attribute yourself. Set it before the first paint, for example from a small inline script in <head>, so a server-rendered page does not flash the wrong mode. This site sets the attribute from its theme toggle, so the page and the demos switch together.

Portaled content takes the page theme

Menus, popovers, tooltips, dialogs and sheets render in a portal at the end of document.body. They take their theme from <html>, not from the scope around their trigger. To keep an overlay in a scoped theme, theme <html> instead, or mount the portal inside the scope. Popover takes a mount prop for this.

A toast has its own theme option. Pass theme: "light" to toaster.show() to render that toast in light mode whatever the page theme. See Toast.

Override tokens with plain CSS

theming/brand-override.tsx
import { Button, Switch } from "@codeui/solid";
import { For } from "solid-js";
import "./brand-override.css";

const scope = {
	display: "flex",
	"flex-direction": "column",
	gap: "var(--cui-space-3)",
	padding: "var(--cui-space-4)",
	"border-radius": "var(--cui-radius-card)",
	background: "var(--cui-surface-canvas)",
	color: "var(--cui-text-default)",
	"min-width": "220px",
} as const;

export default function ThemingBrandOverride() {
	return (
		<div class="docs-brand" style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)" }}>
			<For each={["dark", "light"] as const}>
				{mode => (
					<div data-cui-theme={mode} style={scope}>
						<Switch label="Show line numbers" defaultChecked />
						<Button variant="primary" size="sm">
							Export PNG
						</Button>
						<Button variant="negative" size="sm" class="delete-snippet">
							Delete snippet
						</Button>
					</div>
				)}
			</For>
		</div>
	);
}

The demo scopes its overrides to .docs-brand, so it does not change this site. Here is its stylesheet:

brand-override.css
/* Every mode, including nested data-cui-theme scopes. */
.docs-brand,
.docs-brand [data-cui-theme] {
	--cui-action-brand-base: #7c3aed;
	--cui-radius-scale: 0.5;
}

/* One mode only. */
.docs-brand [data-cui-theme="light"] {
	--cui-surface-canvas: #faf5ff;
	--cui-accent-focus: #7c3aed;
}

.docs-brand [data-cui-theme="dark"] {
	--cui-surface-canvas: #120d1c;
}

/* One instance, with a class on the component. */
.docs-brand .delete-snippet {
	--cui-action-danger-base: #9b2c2c;
	border-radius: 0;
}

In an app, the same stylesheet targets the page instead of a class. This is the complete version, with the system mode covered:

app.css
/* Every mode, including nested data-cui-theme scopes. */
:root,
[data-cui-theme] {
	--cui-action-brand-base: #7c3aed;
	--cui-radius-scale: 0.5;
	--cui-font-family-sans: "IBM Plex Sans", system-ui, sans-serif;
}

/* Light only: an explicit light scope, or the system default. */
:root:not([data-cui-theme]),
[data-cui-theme="light"] {
	--cui-surface-canvas: #faf5ff;
	--cui-accent-focus: #7c3aed;
}

/* Dark only: an explicit dark scope, or the system preference. */
[data-cui-theme="dark"] {
	--cui-surface-canvas: #120d1c;
	--cui-accent-focus: #a78bfa;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-cui-theme]) {
		--cui-surface-canvas: #120d1c;
		--cui-accent-focus: #a78bfa;
	}
}

/* One instance, with a class on the component. */
.delete-snippet {
	--cui-action-danger-base: #9b2c2c;
	border-radius: 0;
}

Load this file anywhere. Order and specificity do not matter against kit rules, because kit rules sit in the cui cascade layer. Among your own rules, the usual order applies, so keep the mode blocks after the shared block.

Which tokens :root alone reaches

The kit sets every token on :root. A token with one value for both modes, such as --cui-radius-scale, --cui-action-brand-base or --cui-font-family-sans, is set only there. Every nested [data-cui-theme] scope inherits it, so an override on :root reaches the whole page.

A token with a dark and a light value, such as --cui-surface-canvas or --cui-accent-focus, is set again on each [data-cui-theme] element. So is every token computed from another token: --cui-focus-color, each radius scaled by --cui-radius-scale, and the brand colors computed from --cui-action-brand-base. Each scope computes them again from the values it inherits, so an override of the source on :root still reaches them. An element with the attribute takes the kit's value for that scope, not the value it would inherit from :root. An override of such a token written only on :root stops at the first nested scope. Write :root, [data-cui-theme] to reach every scope, as app.css does. Tokens shows which tokens have a value per mode. If you set the attribute only on <html>, :root is enough for every token.

Change one instance

Set a token on a class, as .delete-snippet does above. The component resolves var(--cui-…) on its own element, so the new value applies to that instance and its children. A plain property such as border-radius on the same class also wins, for the same cascade layer reason.

Compiled styles

Solid components automatically load the theme and their styles. CSS-only consumers load @codeui/styles/theme.css and the component styles described in Installation. The library generates the theme from DTCG token JSON before publishing. Neither its styles nor your plain CSS overrides require a vanilla-extract plugin in your app.

Change the shape and the brand with two tokens

Two tokens drive the rest:

  • --cui-radius-scale multiplies every radius except none and full. 0 gives square corners, 1 is Inkstone, and values above 1 round them more. The ratio between an inner corner and the corner around it stays the same.
  • --cui-action-brand-base is the brand color. Hover, active, the soft tint, its text, the focus ring and the selection are computed from it with CSS relative colors, so they follow it in both modes. With the Inkstone blue they resolve to the Inkstone values.

Danger, caution and success work the same way: override --cui-action-danger-base and its hover and active follow.

1
ExportedDraft
ExportedDraft
/* Inkstone is the default. No overrides. */

Pick a preset or move the controls, then copy the CSS into your app. Both tokens have one value for both modes, so :root is enough.

PresetOverride
InkstoneNone. This is the default.
Square--cui-radius-scale: 0.35
Soft--cui-radius-scale: 1.5
Forest--cui-action-brand-base: #15803d

The computed colors keep the lightness steps of the Inkstone blue. A brand much lighter or darker than #0076cf can give weak contrast on hover or on soft text. Check the result in both modes, and override the computed token when one falls short. Your override wins, because it sits outside the cui layer.

Browsers without relative colors (Safari before 18, Firefox before 128) keep the Inkstone values for the computed tokens. In those browsers, override each brand token you need, as before.

Find the token to change

Names follow --cui-<role>-<name>. The roles are surface, text, action, accent, border, focus, shadow, radius, space, control, font and motion.

To changeOverride
The brand color--cui-action-brand-base. Hover, active, soft, focus and selection follow it.
The focus ring--cui-accent-focus
Island and page backgrounds--cui-surface-canvas, --cui-surface-panel
Field backgrounds--cui-surface-input
Menus and dialogs--cui-surface-menu, --cui-surface-dialog, --cui-shadow-menu, --cui-shadow-dialog
Every corner--cui-radius-scale
One level of corner--cui-radius-sm, --cui-radius-md and the other radii
The interface font--cui-font-family-sans

Tokens lists all 144 names with their dark and light values. In TypeScript, tokens holds the same names as var(--cui-…) strings.

Keep app resets below the kit

All kit rules live in @layer cui. Unlayered CSS always wins over it, and that includes a CSS reset. An unlayered button { background: none } strips the fill from every kit button. Put the reset in a layer declared before cui. Cascade layers shows how.

On this page