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.
| Group | Examples |
|---|---|
| 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.
- Seeds:
--dui-neutral,--dui-primary,--dui-destructiveand--dui-success. - Scales: neutral and primary each get steps from
50to950. Every step has a fixed lightness, so the seed only sets the hue and how colorful it is, and contrast holds whatever you pick. - Semantic colors: what components read, named after shadcn/ui:
backgroundandforegroundfor the page,primaryfor the main action,mutedfor quiet surfaces and text,destructivefor danger, and so on. Each points at a light and a dark step, likelight-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:
| Seed | Presets |
|---|---|
--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:
: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.