Theming
Colors, border radii, spacing, font sizes and shadows of every component come from CSS variables (prefixed with --hui-) defined in @nscode/theme. Customizing the theme means changing the values of these variables; the component library doesn't need to be rebuilt.
Dark Theme
Add data-theme="dark" to <html> to switch to the dark theme. Remove it or set it to light to go back:
// Switch to dark
document.documentElement.setAttribute('data-theme', 'dark')
// Switch back to light
document.documentElement.setAttribute('data-theme', 'light')
Adding class="dark" to <html> works the same way.
The three cases in order of priority:
data-theme="dark"(orclass="dark") is set: dark;data-theme="light"is set: light, even if the system is in dark mode;data-theme="auto"is set: follow the system's dark mode setting (prefers-color-scheme);- Neither is set: light.
To follow the system theme, explicitly set data-theme="auto" on <html>. Without a theme setting, the page stays light.
The theme prop of HuiConfigProvider is equivalent to setting data-theme on <html> and applies to the whole page. When theme isn't passed, it leaves the page theme alone.
data-theme can also be set on a container in the page so that only that part is dark:
<div data-theme="dark">
<!-- Components in here are dark -->
</div>
Overlays (Select dropdowns, Tooltip, Modal and so on) are mounted under body, outside the container, so they aren't affected by the container's data-theme and keep following the root element's theme.
Palettes
Three palettes are built in: Classic (the default), Jade, and Crimson. Switch between them with data-palette on <html> (or on a container). All support the dark theme. Use the palette button on the right of this site's top bar to preview them.
data-palette | Style | Primary |
|---|---|---|
Not set or classic | Classic | #409eff |
jade | Jade | #18a058 |
crimson | Crimson | #d9262c |
jade is green-based and its success color equals the primary color. In the dark theme its primary color is mint #63e2b7. Saved nature preferences on this site migrate to jade; other removed palettes fall back to classic. Application pages using removed palettes should update data-palette too.
crimson uses red #d9262c as its primary color, a faint pink-white #fffafa page background, and warm dark gray text. Its dark-theme primary color is #e5484d. Both the primary and danger colors are red, so destructive actions such as deletion need explicit text or icons rather than color alone.
document.documentElement.setAttribute('data-palette', 'jade')
// Back to the default palette
document.documentElement.removeAttribute('data-palette')
Custom Variables
Override the variables in your own styles, imported after @nscode/handy-ui/style.css:
:root {
--hui-color-primary: #7c3aed;
--hui-color-primary-light: #8b5cf6; /* hover */
--hui-color-primary-dark: #6d28d9; /* pressed */
--hui-color-primary-bg: #f5f3ff; /* light background in the light theme */
--hui-border-radius: 4px;
}
/* Light background in the dark theme: cover all three ways of enabling it */
:root.dark,
[data-theme='dark'] {
--hui-color-primary-bg: rgba(124, 58, 237, 0.2);
}
@media (prefers-color-scheme: dark) {
:root[data-theme='auto'] {
--hui-color-primary-bg: rgba(124, 58, 237, 0.2);
}
}
A -bg set on :root has the same specificity as the dark theme selectors and comes later, so it still applies in the dark theme, where a light background on a dark page is glaring. That's why it is set again for the dark theme above. In the dark theme, any -bg and -bg-hover you haven't set are computed from the current color (the color at 20% and 30% opacity), so if you only change the color and not -bg, you can leave out the last two blocks.
To change only one page or area, use that container as the selector and add the hui-theme-scope class to the container:
<div class="report-page hui-theme-scope">…</div>
.report-page {
--hui-color-primary: #0f766e;
--hui-color-primary-light: #3f918b;
--hui-color-primary-dark: #0c5e58;
--hui-color-primary-bg: #e7f1f0;
}
The light color scale (--hui-color-primary-light-3 … -light-9) is computed on the element that declares it, from the primary color at that point; child elements inherit the computed result. Only when the container has the hui-theme-scope class is the scale recomputed on the container from the new primary color. The fixed variants -light, -dark and -bg have to be written yourself as above.
To set dark-theme values separately, cover :root.dark, [data-theme='dark'], and :root[data-theme='auto'] inside @media (prefers-color-scheme: dark). See the first example above.
Component Variable Overrides
Public component variables are read with fallbacks, for example color: var(--hui-chip-color, var(--_chip-color)). Component roots, sizes, and states use private --_ defaults rather than redefining public values. Set public values on a component or any ancestor; nested components inherit them, while each instance resets its private defaults. Legacy components are migrated in batches; check each component's documented variables.
Chip uses separate public colors for normal and selected states. Normal --hui-chip-color, --hui-chip-bg, and --hui-chip-border-color values do not override selection. Selected chips read the matching -selected variables, falling back to each instance's selected defaults. Configure both sets on any ancestor:
.chip-colors {
--hui-chip-color: var(--hui-color-danger);
--hui-chip-bg: var(--hui-color-danger-light-9);
--hui-chip-border-color: var(--hui-color-danger);
--hui-chip-color-selected: var(--hui-color-white);
--hui-chip-bg-selected: var(--hui-color-success);
--hui-chip-border-color-selected: var(--hui-color-success);
}
Names follow --hui-<component>[-<part>]-<property>[-<state>], such as --hui-tag-border-color and --hui-scrollbar-thumb-color-hover. Properties include bg, color, border-color, radius, font-size, padding, height, width, and gap. States come last. Renamed variables do not retain aliases.
In scoped application styles, set variables on an ancestor class without :deep():
.profile-panel {
--hui-form-section-title-font-size: 20px;
--hui-form-section-gap: 24px;
}
Use :deep(.hui-xxx__part) only when overriding internal BEM selectors directly, accounting for selector specificity and stylesheet order. Prefer public variables over !important. Scoped styles do not block variable inheritance; reset public values on an inner container when it needs different settings.
Set --hui-splitter-gutter-size on an ancestor to configure Splitter gutters. Without gutterSize, the public value applies with a 6px fallback. An explicit prop wins: :gutter-size="6" overrides an inherited 12px. Nested instances inherit the public variable, while each instance's prop override affects only itself.
.wide-divider {
--hui-splitter-gutter-size: 12px;
}
Variables
Below are the commonly used variables. See packages/theme/src/variables.scss for the full list and dark.scss for the dark theme values.
Colors
Every color has the same set of suffixes. primary can be replaced with success, warning, danger, info or help.
| Variable | Usage |
|---|---|
--hui-color-primary | Primary color |
--hui-color-primary-light, -lighter | One and two steps lighter, often used for hover |
--hui-color-primary-dark, -darker | One and two steps darker, often used for pressed |
--hui-color-primary-bg, -bg-hover | Light background and its hover color, used by alerts and tags |
--hui-color-primary-light-3, -5, -7, -8, -9 | Light scale; larger numbers are lighter. Mixed from the primary and background colors, so they follow changes of color, palette and theme |
There are also --hui-color-white, --hui-color-black and --hui-color-transparent.
Text, Background, Border
| Variable | Usage |
|---|---|
--hui-text-color | Body text |
--hui-text-color-secondary | Secondary text |
--hui-text-color-tertiary | Hints |
--hui-text-color-disabled | Disabled text |
--hui-text-color-placeholder | Placeholder text |
--hui-bg-color | Background of components and the page |
--hui-bg-color-secondary, -tertiary | One and two steps darker, for table headers, stripes and such |
--hui-bg-color-page | Page background (the layer outside the content area) |
--hui-bg-color-hover, -active | Translucent overlay on hover and press |
--hui-bg-color-disabled | Disabled background |
--hui-fill-color, -light, -dark | Fill: slider and progress tracks, skeletons and such |
--hui-mask-color | Mask behind dialogs and drawers |
--hui-border-color | Border |
--hui-border-color-light, -lighter | Lighter borders and dividers |
--hui-border-color-hover | Border of input controls on hover |
Radius, Spacing, Size
| Variable | Value |
|---|---|
--hui-border-radius-sm / --hui-border-radius / -lg / -xl | 2px / 6px / 8px / 12px |
--hui-border-radius-round / -circle | 9999px / 50% |
--hui-spacing-1 … --hui-spacing-12 | From 4px, 4px per step (--hui-spacing-4 is 16px) |
--hui-size-xs / -sm / -md / -lg / -xl | 24px / 32px / 40px / 48px / 56px |
--hui-component-size-large / --hui-component-size / --hui-component-size-small | 40px / 32px / 24px (control height incl. border) |
Typography
--hui-size-* provides general size scales; components do not read these variables. Use --hui-component-size-* for control heights. The default palette uses neutral gray for info in both light and dark themes.
| Variable | Value |
|---|---|
--hui-font-family, --hui-font-family-mono | Body font, monospace font |
--hui-font-size-xs / -sm / -base / -lg / -xl | 12px / 14px / 14px / 16px / 20px |
--hui-font-size-2xl … -5xl | 24px / 30px / 38px / 48px |
--hui-line-height-tight / -normal / -relaxed / -loose | 1.25 / 1.5 / 1.75 / 2 |
--hui-font-weight-normal / -medium / -semibold / -bold | 400 / 500 / 600 / 700 |
Shadow, Transition
| Variable | Usage |
|---|---|
--hui-shadow-sm, --hui-shadow, -md, -lg, -xl, -2xl | Shadows, light to strong |
--hui-transition-duration-fast / -normal / -slow | 150ms / 200ms / 300ms |
--hui-transition-timing-function | Timing function |
The z-index of component overlays (dialogs, drawers, dropdowns, tooltips and so on) isn't controlled by CSS variables. It starts at 2000 and is written in each overlay's inline style. The theme's --hui-z-index-* (1000–1080) are only for utility classes such as hui-z-dropdown and hui-z-modal; changing them doesn't affect component overlays.
Utility Classes
The theme includes a set of utility classes prefixed with hui- that can be used on elements in your pages:
| Category | Examples |
|---|---|
| Text | hui-text-left, hui-text-center, hui-text-primary, hui-text-secondary, hui-ellipsis, hui-ellipsis-2 |
| Background | hui-bg-primary, hui-bg-primary-light, hui-bg-secondary |
| Layout | hui-flex, hui-flex-col, hui-items-center, hui-justify-between, hui-gap-2 |
| Radius, shadow, border | hui-rounded, hui-rounded-lg, hui-shadow, hui-shadow-md, hui-border |
| Other | hui-hidden, hui-cursor-pointer, hui-overflow-auto, hui-w-full |
See packages/theme/src/base.scss for the full list.
Using the Mixins in Your Own SCSS
@nscode/theme also provides SCSS mixins (breakpoints, text truncation, scrollbars, flex layout and more). Projects using SCSS can import them:
@use '@nscode/theme/scss/mixins.scss' as ns;
.title {
@include ns.text-ellipsis(2);
}
.sidebar {
// Breakpoints: sm 640px, md 768px, lg 1024px, xl 1280px, 2xl 1536px
@include ns.breakpoint-down('md') {
display: none;
}
}
Import only mixins. Don't @use '@nscode/theme' as a whole in component styles; that outputs all the variables and reset styles again.