Skip to content

Theming

Override any token in your CSS:

:root {
--accent: oklch(55% 0.2 250);
--radius: 0.5rem;
}

See the Tokens reference for all available variables.

The library automatically supports dark mode based on the user’s system preference via prefers-color-scheme.

By default, dark mode activates when the user’s system is set to dark mode. No additional configuration required.

Force a specific theme using the data-theme attribute on the root element:

<!-- Force light mode -->
<html data-theme="light">
<!-- Force dark mode -->
<html data-theme="dark">
function toggleTheme() {
const current = document.documentElement.getAttribute("data-theme");
const next = current === "dark" ? "light" : "dark";
document.documentElement.setAttribute("data-theme", next);
}
<Button onClick={toggleTheme}>Toggle Theme</Button>

The library uses CSS custom properties that update based on theme:

  • Light mode: High lightness values for backgrounds, low for text
  • Dark mode: Inverted - low lightness backgrounds, high lightness text
  • All semantic tokens (--bg, --fg, --border, etc.) automatically adapt

The library uses CSS cascade layers to provide predictable specificity and easy overriding.

Styles are organized into four layers, listed from lowest to highest priority:

LayerPurpose
resetMinimal CSS reset and base element styles
tokensDesign tokens (CSS custom properties)
componentsComponent styles (.btn, .card, .modal, etc.)
utilitiesUtility classes (.stack, .row, .text-muted, etc.)

Since library styles are in layers, your unlayered CSS automatically takes precedence:

/* Your styles override library styles by default */
.btn {
border-radius: 9999px; /* pill-shaped buttons */
}

For more control, define your styles in a higher-priority layer:

@layer base, overrides;
@layer overrides {
.btn {
text-transform: uppercase;
}
}

When importing, the layer order is established by the first import:

/* Establish layer order first */
@layer reset, tokens, components, utilities, app;
/* Then import library styles */
@import "@f0rbit/ui/styles";
/* Your app layer has highest priority */
@layer app {
.card {
background: var(--bg-alt);
}
}