Theme Customisation & Palette Tokens
How to configure, override, and create custom color palettes using IBM Carbon v11 tokens and SCSS compilation.
The Hugo-Carbon Theme Engine delivers client-side theme switching and compile-time token configuration without requiring CSS file swapping or full page reloads.
1. Dual-Style Architecture: Light & Dark
The design system implements a clean, accessible dual-style architecture:
| |
Core Token Mapping Reference
| Token Name | Light Style (White) | Light Variant (Gray 10) | Dark Style (Gray 100) | Dark Variant (Gray 90) | Description |
|---|---|---|---|---|---|
--cds-background | #ffffff | #f4f4f4 | #161616 | #262626 | Default page canvas |
--cds-layer-01 | #f4f4f4 | #ffffff | #262626 | #393939 | Container elevation level 1 |
--cds-layer-02 | #e0e0e0 | #e0e0e0 | #393939 | #525252 | Container elevation level 2 |
--cds-text-primary | #161616 | #161616 | #f4f4f4 | #f4f4f4 | High-contrast body text |
--cds-text-secondary | #525252 | #525252 | #c6c6c6 | #c6c6c6 | Metadata and helper text |
--cds-interactive-01 | #0f62fe | #0f62fe | #0f62fe | #0f62fe | Primary action button / links |
--cds-focus | #0f62fe | #0f62fe | #ffffff | #ffffff | Accessible 2px focus ring |
2. Real-Time Theme Switching Mechanism
The theme switcher provides three user-facing options: Browser Default (system), Light (light), and Dark (dark).
Active visual styling is applied to <html> via data-carbon-theme="light" or data-carbon-theme="dark". The inline <head> script reads localStorage synchronously before initial render to prevent flash-of-unstyled-content (FOUC).
| |
When set to system, changes to the operating system’s prefers-color-scheme automatically update the visual mode in real time.
3. Per-Domain Custom Colour Configuration
Each website repository or subdomain customises its brand colors independently in hugo.yaml under params.carbon.theme.
Example: Custom Brand Colors in hugo.yaml
| |
The Hugo engine injects these overrides at build time directly into scoped CSS selectors (html[data-carbon-theme="light"] and html[data-carbon-theme="dark"]), ensuring full WCAG 2.1 AA contrast compliance across both styles.