Buy me a coffee

Theming

Every color, corner, space and animation comes from a token. Change a token and every component follows.

The tokens

Tokens are CSS custom properties that start with --dui-. After installing, they live in your own project, all in one file: src/lib/styles/distill-ui/tokens.css.

GroupExamples
Presets--dui-blue, --dui-violet…, --dui-gray-slate…
Seeds--dui-neutral, --dui-primary, --dui-destructive, --dui-success
Scales--dui-neutral-50 to -950, --dui-primary-50 to -950
Colors--dui-color-background, --dui-color-primary, --dui-color-muted-foreground…
Corners--dui-radius (scales --dui-radius-sm to -xl)
Spacing--dui-space-1 (0.25rem) to --dui-space-12 (3rem)
Text--dui-font-sans, --dui-font-mono, --dui-text-xs to -lg, --dui-weight-*
Shadows--dui-shadow-xs to -lg
Motion--dui-duration-fast|normal|slow, --dui-ease-*

Colors

Colors work in three layers. You only ever change the first.

  1. Seeds: --dui-neutral, --dui-primary, --dui-destructive and --dui-success.
  2. Scales: neutral and primary each get steps from 50 to 950. Every step has a fixed lightness, so the seed only sets the hue and how colorful it is, and contrast holds whatever you pick.
  3. Semantic colors: what components read, named after shadcn/ui: background and foreground for the page, primary for the main action, muted for quiet surfaces and text, destructive for danger, and so on. Each points at a light and a dark step, like light-dark(var(--dui-primary-500), var(--dui-primary-400)).

Presets

tokens.css comes with ready-made colors to point the seeds at. Switching is one word:

SeedPresets
--dui-primary--dui-blue (default), --dui-cyan, --dui-violet, --dui-forest, --dui-ember
--dui-neutral--dui-gray-slate (default), --dui-gray-neutral, --dui-gray-stone

For a color of your own, set the seed to any oklch() value instead.

Dark mode

Out of the box, the theme follows the visitor's system setting. To choose for them, set data-theme (or class="dark" / class="light") on the <html> element:

<!-- Follow the visitor's system setting (the default) -->
<html>

<!-- Always dark, or always light -->
<html data-theme="dark">
<html data-theme="light">

Every color has a light and a dark value, and data-theme works on any element, not just <html>. Components never check the theme themselves.

Make it yours

tokens.css is yours to edit, the same as the components. To rebrand, change the seeds, or let the theme builder pick them for you:

src/lib/styles/distill-ui/tokens.css
:root {
	/* A preset, or any oklch() like oklch(0.6 0.18 330) */
	--dui-primary: var(--dui-violet);
	--dui-neutral: var(--dui-gray-stone);

	/* One value scales every corner: 0 for square, 1rem for soft. */
	--dui-radius: 0.375rem;
	--dui-font-sans: 'Inter', system-ui, sans-serif;
}

Theming part of a page

Set seeds on any element with class="dui-theme" and the colors are worked out again for everything inside it:

<section class="dui-theme promo">
	<Button>Upgrade</Button>
</section>

<style>
	.promo {
		--dui-primary: oklch(0.6 0.19 150);
	}
</style>

Reduced motion

When someone's system asks for reduced motion, every duration token becomes 0ms, so dialogs and menus appear without animating. You don't need to do anything for this.

Next: Theme builder →