@kimen/tokens
Kimen design tokens: DTCG JSON sources compiled to CSS custom properties
(--ki-*). Part of Kimen, an AI-first
Web Components foundation for generative UI.
Status: pre-v1, published on npm. Before 1.0.0 a minor release may break
the public API. The instructions below are validated in CI against the
packed tarballs of every release run, dry runs included.
Install
pnpm add @kimen/tokens
# or: npm install @kimen/tokens
Stylesheets
The package exports these stylesheets:
| Export |
What it is |
@kimen/tokens/css/core |
The onmars default theme without component tokens: every other --ki-* token, both schemes, the color-scheme contract they resolve from, densities and preference modes |
@kimen/tokens/css/ki-<tag> |
One sheet per ki-* tag: the component tokens that tag needs, including those of the components it renders |
@kimen/tokens/css/base |
The page contract: page background/foreground and body font, painted from tokens, and group items laid out as blocks until their tags register |
@kimen/tokens/css |
The full sheet, the simple alternative to the core and the tag sheets: every --ki-* token of the onmars default theme in one stylesheet |
@kimen/tokens/css/material3 |
The Material 3 reference theme: its overrides of the default theme, opt-in via data-ki-theme |
@kimen/tokens/css/onmars-fonts.css |
Optional Instrument Sans and Newsreader for onmars v2 |
@kimen/tokens/css/material3-fonts.css |
Optional local metric-adjusted fallback for self-hosted Roboto |
Load the core and the page contract once per page. Then load one sheet for
every ki-* tag the page uses, named like the element import, and any other
stylesheet alongside them:
import '@kimen/tokens/css/core';
import '@kimen/tokens/css/ki-button'; // beside '@kimen/elements/ki-button'
import '@kimen/tokens/css/ki-input'; // beside '@kimen/elements/ki-input'
import '@kimen/tokens/css/base'; // page contract: paint the page, lay out items before registration
import '@kimen/tokens/css/material3'; // optional: a second theme
A theme stylesheet declares only the tokens it changes, so it does nothing on
its own: the core and the tag sheets (or the full sheet) must be loaded too.
- One sheet per tag you use. A tag's sheet already carries the tokens of
every component that tag renders in its shadow tree:
css/ki-pagination
brings the icon and icon-button tokens it paints with. Your own markup is
your own, though: a ki-button slotted into a ki-card needs
css/ki-button too, and a ki-tabs needs css/ki-tab and
css/ki-tab-panel for the tabs and panels you slot into it. A tag
rendered without its sheet paints with undefined tokens.
- Same values. Every declaration in the core and the tag sheets is the
full sheet's own. Loading the full sheet as well changes nothing.
- Overrides keep working. The core declares its tokens exactly as the
full sheet does, so a page override of a core token comes after the core.
A tag sheet declares its tokens at zero specificity
(
:where(:root), :where([data-ki-theme])). A page's :root or theme-root
override of a component token therefore wins in any order, including when
a bundler inserts a route's tag sheet after the page's stylesheet. Themes
(@kimen/tokens/css/material3), preference modes and densities apply as
with the full sheet.
- No foundations. The core and tag sheets omit the
--ki-foundation-*
tokens. material3 inlines the expressions it needs. The full sheet keeps
only the four --ki-foundation-onmars-v1-* values for the legacy dialog
and tooltip appearance until 1.0.0.
- Script that reads a component token on the root with
getPropertyValue()
gets an empty string while that tag's sheet is not loaded.
The simple alternative: the full sheet
@kimen/tokens/css declares every public token in one stylesheet, in place
of the core and the tag sheets:
import '@kimen/tokens/css';
import '@kimen/tokens/css/base';
There is nothing to keep in step with the page's markup, at the cost of
shipping the tokens of components the page never shows:
| Page |
Core and tag sheets |
Full sheet |
One ki-button |
8.1 KB |
18.9 KB |
| Ten components |
11.2 KB |
18.9 KB |
Sizes are minified and brotli-compressed, as a bundler ships them. Use the
full sheet when a page uses most of the catalog, where it is the smaller of
the two, or when the page cannot list its tags in advance: a generative UI
surface renders whatever catalog components the agent picks.
The page contract
Tokens are custom properties: loading them paints nothing. @kimen/tokens/css/base
paints the page from them — background from --ki-surface-base, text from
--ki-text-high-em, body family from --ki-typography-family-body. It
publishes no tokens of its own — it only consumes them, so it never widens the
token surface — and it declares no colour scheme: the token stylesheet owns
that.
It also covers the time before the component scripts run. An unregistered
custom element is an inline box, so three ki-segment labels read as one
word. Until each tag registers, the page contract lays out the items of
Kimen groups as blocks: segments, radios, checkboxes, options, and menu,
list, tab, tree, step, timeline, sidebar and mobile-nav items. The rule is
:where(…):where(:not(:defined)) { display: block }: no paint, zero
specificity, nothing once the tag is defined.
Skipping it is supported in both schemes: the page keeps the browser's own
canvas and text colour for the active scheme, and every component stays
legible on it (measured over every component under a dark system preference
by bare-page.browser.spec.ts).
Theme and scheme selection
Two attributes drive everything, on the document root or on any element:
<html data-ki-theme="material3" data-ki-color-scheme="dark">
data-ki-color-scheme: light or dark forces a scheme for any theme.
Without it the page follows the system preference: the token stylesheet
declares color-scheme: light dark on the root as a default, and the
attribute pins it.
data-ki-theme: opts into a non-default theme. Unknown theme names and
missing theme stylesheets fall back to onmars through the cascade. No
runtime code is involved anywhere.
How the scheme works
The scheme is a single declaration, color-scheme, and every
scheme-dependent token is a single light-dark() value that resolves from it:
:where(:root) {
color-scheme: light dark;
}
[data-ki-color-scheme='dark'] {
color-scheme: dark;
}
:root,
:where([data-ki-theme]) {
--ki-surface-s0: light-dark(var(--ki-color-white-100), var(--ki-color-dark-950));
}
The same declaration tells the browser which canvas, scrollbars, native
controls and autofill to paint, so the two cannot disagree. Consequences:
- Kimen follows the page's
color-scheme, not prefers-color-scheme
directly. The default is declared with :where(), at zero specificity, so
any color-scheme your own CSS declares for the document wins —
html { color-scheme: light } is enough, before or after the token
stylesheet — and the tokens follow it. It has to be CSS: a
<meta name="color-scheme"> alone does not pin the page once a stylesheet
declares the property on the root.
data-ki-color-scheme is the explicit declaration: on the root it wins
over an html { color-scheme } rule of the page.
- Reassign a scheme-dependent token with both values
(
light-dark(#fff, #111)); a single value applies to both schemes.
- A scheme-dependent token only becomes a colour where it is used. Script
reading one with
getPropertyValue() gets the light-dark() pair; read
the computed color of an element that uses the token instead.
light-dark() is Baseline (Chrome 123, Firefox 120, Safari 17.5), inside the
library's browser baseline.
Subtrees
Both attributes work on any element — an island of generated UI embedded in a
page it does not own can carry its own theme and scheme:
<section data-ki-theme="material3" data-ki-color-scheme="dark">…</section>
<section data-ki-theme="onmars">…</section> <!-- back to the default theme -->
A scheme subtree redeclares nothing (light-dark() resolves where a token is
used). A themed subtree redeclares every token on its own root so that every
alias is recomputed there; that is also the element to reassign tokens on,
palette included — [data-ki-theme='acme'] { --ki-color-brand-500: … }
restyles every semantic token, tint and translucent variant built on that
step inside the region. A name without a theme stylesheet starts from
onmars, so on a page with its own theme a region that adjusts a few tokens
repeats that theme's name (<section data-ki-theme="acme" class="sheet">,
the .sheet rule after the theme rule); another name drops the page theme.
A reassignment on a plain element (.acme) changes that custom property and
none of the tokens that alias it, so the region keeps the page's semantic
values and component tokens such as --ki-button-*. Page aliases of Kimen
tokens follow the same rule: declare them on :root, [data-ki-theme].
Neither attribute paints the element that carries it: give a region its
surface with
background-color: var(--ki-surface-s0); color: var(--ki-text-high-em).
Preference modes
Two modes reassign part of the token set on top of whatever theme and scheme
are active (specs 043 and 044):
| Mode |
Activated by |
What changes |
| more contrast |
prefers-contrast: more, data-ki-contrast="more" |
neutral text ≥ 7:1, neutral control boundaries ≥ 4.5:1, separators and container edges ≥ 3:1, a 3px focus ring; implies reduced transparency |
| reduced transparency |
prefers-reduced-transparency: reduce, data-ki-transparency="reduce", more contrast |
every content surface opaque (surface-special-* glass, surface-*-tint), no backdrop blur; state washes and the modal scrim keep their alpha |
The value a token takes under a mode is a token of its own,
--ki-<mode>-<token>: --ki-contrast-more-outline-control,
--ki-reduced-transparency-surface-primary-tint. These mode tokens are
declared with every other token, next to the token they replace in the DTCG
sources (ki.contrast-more.*, ki.reduced-transparency.*), and a theme
overrides them like any other (material3 sets two). A deprecated token has
no mode token: its replacement carries the mode. Under the mode, on the
root and on every theme root, the stylesheet re-points each reassigned token
to its mode token with !important, under the media query and under the
declaration. An important declaration outranks every normal one, so the mode
applies over any theme, whatever its specificity or load order. The
declarations only switch a mode on; they take effect on the root and on
theme roots, because those are the elements that redeclare every alias.
A theme of your own needs nothing to follow the modes. To choose its own
mode values it sets the mode tokens, at normal priority; setting the token
itself under the mode has no effect any more. The token reference lists
every token each mode reassigns, its mode token and Kimen's value
(Preference modes):
[data-ki-theme='acme'] {
--ki-outline-control: #8c857c;
--ki-contrast-more-outline-control: light-dark(#4a4540, #c4bdb4); /* only under more contrast */
}
pnpm --filter @kimen/tokens contrast sweeps every theme × scheme in the
standard appearance and in each mode, with the stronger thresholds under more
contrast. The public token surface publishes each mode as its own context
(contrast-more/light, reduced-transparency/dark, …).
Density
data-ki-density="compact" on any element makes its region compact,
data-ki-density="touch" gives it 44 × 44 pointer targets, and
data-ki-density="default" restores the default inside it (spec 045 and its
Amendment A1). Three tokens carry the level and are inherited from the
document: declared once in their own :root rule, never redeclared on a
theme root, and read by component CSS where a size is used — so the
declaration reaches every component inside the element, in any theme, and
the nearest declaration wins by plain inheritance. Every level's rule
declares all three, so a level nested in another is that level through and
through:
| Token |
Default |
Compact |
Touch |
Used for |
--ki-density-control-offset |
0 |
-0.5rem |
0.25rem |
added to the block size of buttons, fields, selects, options, list items, tabs; icon buttons take a negative step only |
--ki-density-space-scale |
1 |
0.75 |
1 |
multiplies the padding and gaps of cards, dialogs, alerts, lists, listboxes, tab panels, tooltips |
--ki-density-target-min |
24px |
24px |
44px |
the pointer target every interactive control reaches (WCAG 2.5.8; 2.5.5 in touch): a control painted smaller extends its target without painting more |
The build marks the inherited tokens with
$extensions["dev.kimen"].inherit = "document" and fails if a token aliases
them or a theme or mode reassigns them or what they reference. The levels
live in tokens/modes/compact.tokens.json and tokens/modes/touch.tokens.json.
Touch is opt-in: no Kimen stylesheet applies it under a coarse pointer. A
page that wants that writes it in its own stylesheet, after Kimen's:
@media (pointer: coarse) {
:root {
--ki-density-control-offset: var(--ki-space-xs);
--ki-density-space-scale: var(--ki-scale-unit);
--ki-density-target-min: var(--ki-size-target-touch);
}
}
Layer model
The token graph is layered primitive → theme → semantic → component: