Theme:

Themes

DengaUI ships with five built-in themes powered by CSS custom properties. Switch themes instantly with a single attribute.

Switching Themes

Set the data-theme attribute on any parent element. Typically you set it on <html> to theme the entire page:

<html data-theme="denga-light"> <!-- All components use the light theme --> </html>

Switch themes at runtime with JavaScript:

// Switch to dark theme document.documentElement.setAttribute('data-theme', 'denga-dark'); // Or read the current theme const current = document.documentElement.getAttribute('data-theme');

You can also scope themes to a section of the page. Child elements inherit the closest ancestor's theme:

<html data-theme="denga-light"> <body> <button class="dui-btn dui-btn-primary">Light theme button</button> <div data-theme="denga-dark" style="padding: 1rem;"> <button class="dui-btn dui-btn-primary">Dark theme button</button> </div> </body> </html>

Built-in Themes

DengaUI includes five carefully crafted themes. Click the theme buttons in the top bar to preview them live on this page.

Theme Value Description
Denga Light denga-light Clean light theme with blue primary. Default.
Denga Dark denga-dark Dark companion to the default light theme.
Savanna savanna Warm earthy tones inspired by the African savanna.
Midnight midnight Deep dark theme with rich contrast and purple accents.
Sunrise sunrise Bright and warm with orange and coral tones.
Success Warning Error

Auto Dark Mode

Respect the user's system preference with a small JavaScript snippet. This switches between denga-light and denga-dark based on prefers-color-scheme:

// Place in <head> or early in your JS to avoid flash const prefersDark = window.matchMedia('(prefers-color-scheme: dark)'); function applySystemTheme() { const theme = prefersDark.matches ? 'denga-dark' : 'denga-light'; document.documentElement.setAttribute('data-theme', theme); } // Apply on load applySystemTheme(); // React to system changes prefersDark.addEventListener('change', applySystemTheme);

To let users override the system preference, store their choice in localStorage and check it first:

function getTheme() { const saved = localStorage.getItem('theme'); if (saved) return saved; return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'denga-dark' : 'denga-light'; } function setTheme(name) { document.documentElement.setAttribute('data-theme', name); localStorage.setItem('theme', name); } // Initialize setTheme(getTheme());

Custom Themes

Create your own theme by defining CSS custom properties under a [data-theme] selector. All DengaUI components read from these variables, so changing them recolors everything automatically:

/* In your CSS file, after @plugin "dengaui" */ [data-theme="ocean"] { --dui-color-primary: oklch(0.55 0.18 240); --dui-color-primary-content: oklch(0.98 0 0); --dui-color-secondary: oklch(0.60 0.12 200); --dui-color-secondary-content: oklch(0.98 0 0); --dui-color-accent: oklch(0.70 0.15 180); --dui-color-accent-content: oklch(0.15 0 0); --dui-color-neutral: oklch(0.35 0.02 240); --dui-color-neutral-content: oklch(0.90 0 0); --dui-color-base-100: oklch(0.15 0.02 240); --dui-color-base-200: oklch(0.20 0.02 240); --dui-color-base-300: oklch(0.28 0.02 240); --dui-color-base-content: oklch(0.90 0.01 240); --dui-color-info: oklch(0.65 0.15 230); --dui-color-info-content: oklch(0.98 0 0); --dui-color-success: oklch(0.65 0.18 155); --dui-color-success-content: oklch(0.98 0 0); --dui-color-warning: oklch(0.75 0.15 80); --dui-color-warning-content: oklch(0.15 0 0); --dui-color-error: oklch(0.60 0.20 25); --dui-color-error-content: oklch(0.98 0 0); --dui-radius-sm: 0.25rem; --dui-radius-md: 0.5rem; --dui-radius-lg: 1rem; }

Then use it like any built-in theme:

<html data-theme="ocean">

CSS Variable Reference

Every theme must define the following CSS custom properties. All color values use the oklch() color space for perceptual uniformity:

Brand Colors

--dui-color-primary /* Primary brand color */ --dui-color-primary-content /* Text on primary backgrounds */ --dui-color-secondary /* Secondary brand color */ --dui-color-secondary-content /* Text on secondary backgrounds */ --dui-color-accent /* Accent / highlight color */ --dui-color-accent-content /* Text on accent backgrounds */ --dui-color-neutral /* Neutral / muted color */ --dui-color-neutral-content /* Text on neutral backgrounds */

Base / Surface Colors

--dui-color-base-100 /* Page background */ --dui-color-base-200 /* Slightly darker surface (cards, inputs) */ --dui-color-base-300 /* Borders, dividers, subtle backgrounds */ --dui-color-base-content /* Default text color on base surfaces */

State Colors

--dui-color-info /* Informational */ --dui-color-info-content /* Text on info backgrounds */ --dui-color-success /* Success / positive */ --dui-color-success-content /* Text on success backgrounds */ --dui-color-warning /* Warning / caution */ --dui-color-warning-content /* Text on warning backgrounds */ --dui-color-error /* Error / destructive */ --dui-color-error-content /* Text on error backgrounds */

Layout Tokens

--dui-radius-sm /* Small border radius (badges, inputs) */ --dui-radius-md /* Medium border radius (buttons, cards) */ --dui-radius-lg /* Large border radius (modals, drawers) */

You can reference these variables directly in your own styles:

/* Your custom CSS */ .my-sidebar { background-color: var(--dui-color-base-200); border-right: 1px solid var(--dui-color-base-300); color: var(--dui-color-base-content); } .my-highlight { background-color: var(--dui-color-primary); color: var(--dui-color-primary-content); border-radius: var(--dui-radius-md); }
← Usage Next: Button →