@kernelui-lib/styles
v1.0.0
Published
Kernel design tokens: CSS custom properties, baseline reset, and an optional Tailwind v4 bridge.
Maintainers
Readme
@kernelui-lib/styles
The token layer underneath every Kernel component. No JavaScript, no build step, just CSS custom properties.
Usage
Plain CSS or CSS Modules, no Tailwind:
@import "@kernelui-lib/styles";That's tokens.css (all the custom properties) plus reset.css (a deliberately small baseline). Import them separately if you want the tokens without the reset:
@import "@kernelui-lib/styles/tokens.css";With Tailwind v4:
@import "tailwindcss";
@import "@kernelui-lib/styles/tokens.css";
@import "@kernelui-lib/styles/tailwind.css";The Tailwind bridge maps every token into @theme inline, so bg-accent, text-muted, rounded-md and so on resolve to the same values the components use. There's one source of truth either way.
The colour scale
Every colour role (gray, accent, plus the status colours) follows Radix Colors' 12-step model: each step has exactly one job, so you never have to guess which shade of a colour to reach for.
| Step | Use case | | --- | --- | | 1–2 | Backgrounds (app background, subtle background) | | 3–5 | Component backgrounds (resting, hover, pressed/selected) | | 6–8 | Borders (non-interactive, interactive, hover) | | 9–10 | Solid backgrounds (normal, hover) | | 11–12 | Text (low-contrast, high-contrast) |
Component CSS never reaches for a raw step directly. It reads semantic aliases (--kernel-color-surface, --kernel-color-border-interactive, --kernel-color-text-muted, and so on) that point at a specific step, so the mapping stays legible and the underlying scale can be restyled without touching a single component.
Unlike Radix's hand-picked swatches, Kernel generates all 12 steps from one hue and one chroma value per role using OKLCH, which is what makes the whole ramp reshade from a single change. The trade-off: Radix calibrates each hue individually against APCA contrast targets, Kernel uses one shared lightness/chroma curve for every hue. It's close, not identical, across very different hues, and it's why --kernel-hue-accent should be treated as "pick any hue and it'll look reasonable", not "guaranteed as vivid as it could be at that hue". For that, use a named theme (below).
Named accent themes
Seven named accent presets ship in themes/: amber, blue, green, orange, red, teal, and violet. They are generated by scripts/generate-accent-themes.mjs. Unlike the live --kernel-hue-accent curve above, every one of their 12 steps is individually checked against the sRGB gamut for that exact hue and lightness, and set to the punchiest chroma that still fits, rather than one flat chroma value applied everywhere. Real Radix does this by hand, per swatch; this script does the equivalent check programmatically with culori, which is why it only exists for a fixed set of hues chosen ahead of time rather than for any hue you type in live.
The names are verified against OKLCH-converted reference swatches (see the script), not eyeballed, on the theory that a colour called "Violet" should render as violet.
@import "@kernelui-lib/styles/themes/blue.css";<html data-kernel-accent="blue">Or pull in every preset at once for a theme switcher (see the docs site's homepage for a live example):
@import "@kernelui-lib/styles/themes/index.css";Regenerate after changing a hue or adding a theme:
bun run generate:themesChanging the theme
Override any token on :root, after importing:
:root {
--kernel-hue-accent: 150; /* whole accent ramp shifts to green */
--kernel-radius-base: 0.25rem; /* every radius in the system sharpens up */
}Scope a theme to part of a page by overriding tokens on a container instead of :root:
.marketing-section {
--kernel-hue-accent: 25; /* red, not "340", see the note above about checking a hue before naming it */
}Light and dark are handled by light-dark() and follow prefers-color-scheme automatically. Force one explicitly with data-theme="light" or data-theme="dark" on html or any container.
