Skip to content

Runtime API

The Runtime API allows you to manage the theme mode and sync it with the browser environment.

The ThemeManager class is the main entry point for runtime theme control.

import { ThemeManager } from "@axiomatic-design/color/browser";
const themeManager = new ThemeManager(options?: ThemeManagerOptions);

Options:

OptionTypeDefaultDescription
rootHTMLElementdocument.documentElementThe element to apply the theme to.
lightClassstringundefinedClass to add in light mode. If omitted, sets style="color-scheme: light".
darkClassstringundefinedClass to add in dark mode. If omitted, sets style="color-scheme: dark".
faviconGenerator(color: string) => stringundefinedFunction to generate an SVG favicon based on the current theme color.

Sets the active theme mode.

  • mode: "light" | "dark" | "system"
themeManager.setMode("dark");

Returns the current configured mode (e.g., "system").

Returns the actual active mode ("light" or "dark"). If mode is "system", this returns the OS preference.

Cleans up event listeners (e.g., for system preference changes). Call this when unmounting your app or component.

Updates the <meta name="theme-color"> tag to match the computed background color of the document body. This is called automatically by ThemeManager, but you can export and use it manually if needed.

import { updateThemeColor } from "@axiomatic-design/color/browser";
updateThemeColor();

Updates the favicon dynamically.

import { updateFavicon } from "@axiomatic-design/color/browser";
updateFavicon(
(color) => `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<circle cx="16" cy="16" r="14" fill="${color}" />
</svg>
`
);