Tokens and Theming
Batoi UIF themes should be driven by explicit tokens instead of one-off visual overrides.
The Theme Builder example demonstrates how a client-side tool can adjust tokens and export application-ready CSS.
Token Pipeline
Core Tokens
| Token | Purpose |
|---|---|
--uif-color-primary | Primary brand/action color |
--uif-accent | Supporting accent color |
--uif-text | Main text color |
--uif-surface | Primary surface color |
--uif-radius-md | Standard card radius |
--uif-space-4 | Standard spacing unit |
--uif-font-family | Font stack |
UIF 2.2.0 also provides semantic typography weights, line heights, tracking, readable content measures, responsive title sizes, and text utilities. The default stack uses system fallbacks and does not require a webfont download.
Use helpers such as uif-page-title, uif-section-title, uif-component-title, uif-label, uif-caption, and uif-prose to preserve hierarchy. Size, weight, line-height, alignment, muted-text, and semantic-color utilities are available for smaller adjustments.
Example CSS
:root {
--uif-color-primary: #0f70b7;
--uif-accent: #00a999;
--uif-text: #1e293b;
--uif-surface: #ffffff;
--uif-radius-md: 8px;
--uif-space-4: 1rem;
--uif-font-family: Inter, Arial, sans-serif;
}Default palette and scales
These values are checked against the bundled UIF 4.0.0 token stylesheet. Theme overrides can change them. An application token with a similar name is not necessarily consumed by native components.
| Semantic color | Token | Default |
|---|---|---|
| Primary | --uif-color-primary | #0e68b0 |
| Secondary | --uif-color-secondary | #64748b |
| Success | --uif-color-success | #16835f |
| Danger | --uif-color-danger | #c9363e |
| Warning | --uif-color-warning | #b66a09 |
| Info | --uif-color-info | #087f9c |
--uif-accent defaults to the primary color. Use surface, text, and border tokens with semantic colors; do not assume white text is accessible on every custom palette. Test hover, focus, and disabled states after customization.
Typography
--uif-font-sans defaults to Inter, proxima-nova, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; --uif-font-family references it. Font names do not download fonts. --uif-font-mono defaults to "SFMono-Regular", Consolas, "Liberation Mono", monospace.
Token suffix on --uif-text- | xs | sm | md | lg | xl | 2xl | 3xl | 4xl |
|---|---|---|---|---|---|---|---|---|
| rem | .75 | .875 | 1 | 1.125 | 1.375 | 1.75 | 2.25 | 3 |
| Line-height token | Unitless value |
|---|---|
--uif-leading-tight | 1.1 |
--uif-leading-title | 1.18 |
--uif-leading-body | 1.58 |
--uif-leading-relaxed | 1.7 |
Weight tokens --uif-weight-regular/medium/semibold/bold are 400/500/600/700. Semantic weights select these for controls, headings, labels, and metrics. Prefer uif-page-title, uif-section-title, and uif-component-title over manually combining arbitrary weights and sizes. Page-title size uses clamp(1.85rem, 2.7vw, 2.4rem); section-title size uses clamp(1.35rem, 1.7vw, 1.7rem). Copy measure is 68ch and wide measure is 82ch.
Spacing
The native family is --uif-space-*, not --batoi-space-*.
| Token suffix | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| rem | .25 | .5 | .75 | 1 | 1.5 | 2 | 3 | 4 |
| px at a 16px root | 4 | 8 | 12 | 16 | 24 | 32 | 48 | 64 |
Token availability does not imply a utility exists for every number. See Utilities for supported ranges.
Breakpoints and containers
Reference tokens --uif-breakpoint-sm/md/lg are 36rem/48rem/72rem. At a 16px initial font size these correspond to 576/768/1152px. They describe reference values, not configurable media-query switches: CSS custom properties cannot be substituted into ordinary media-query conditions.
Actual component queries vary. The 12-column form grid becomes one column at a viewport width of 48rem or less, resetting its spans. Utility grids use a 40rem container query. The uif-container utility establishes that query container and currently caps width at 72rem; do not assume the --uif-container token (76rem) controls that utility. Changing a breakpoint token alone does not rewrite these CSS rules.
Guidance
- Keep token names stable.
- Avoid per-page color overrides where tokens are enough.
- Preview themes against forms, cards, tables, and primary actions.
- Export CSS and JSON when a theme needs to move between applications.
Implement Light and Dark Modes
Define both modes with the same semantic token names. Components should consume surface, text, border, brand, and status tokens without testing the current mode themselves.
:root,
[data-theme="light"] {
color-scheme: light;
--uif-surface: #ffffff;
--uif-surface-elevated: #f8fafc;
--uif-text: #1e293b;
--uif-text-muted: #64748b;
--uif-border: #cbd5e1;
}
[data-theme="dark"] {
color-scheme: dark;
--uif-surface: #101a2a;
--uif-surface-elevated: #172235;
--uif-text: #f1f5f9;
--uif-text-muted: #b6c2d1;
--uif-border: #3b4a60;
}Use an explicit user choice when one exists and otherwise follow the operating-system preference. Persist only the mode name, not a complete token payload.
const root = document.documentElement;
const stored = localStorage.getItem('theme');
const preferred = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
function applyTheme(theme) {
const next = theme === 'dark' ? 'dark' : 'light';
root.dataset.theme = next;
root.style.colorScheme = next;
}
applyTheme(stored || preferred);
document.querySelector('[data-theme-toggle]')?.addEventListener('click', () => {
const next = root.dataset.theme === 'dark' ? 'light' : 'dark';
localStorage.setItem('theme', next);
applyTheme(next);
});Place the initial mode script in the document head when possible so the correct surface is applied before first paint. A toggle must have an accessible name and expose its current state. Verify text, links, focus indicators, controls, disabled states, alerts, tables, charts, images, and code blocks in both modes. Do not invert photographs or logos with a blanket CSS filter.
The UIF 2.3.0 examples follow this pattern: the selected mode is persisted, applied before the example renders, and paired with the appropriate light or dark UIF logo asset.