Theme Utilities

Dynamic theming driven by CSS custom properties. Apply a theme class to an element (or <body>) to swap the color tokens used across the framework.

Interactive demo

This box is bound to a theme class. Switch between light and dark below.

$
JS
const demo = document.getElementById('theme-demo');
const toggle = document.getElementById('theme-toggle');

toggle.addEventListener('click', () => {
  demo.classList.toggle('ms-theme-dark');
  demo.classList.toggle('ms-theme-light');
});

Theme classes

ClassDescription
ms-theme-lightLight theme (default color tokens).
ms-theme-darkDark theme color tokens.
ms-theme-systemReserved class — tokens are set by JS to match the system preference.
ms-theme-toggleStyles a fixed, top-right theme toggle button.
ms-theme-transitionSmoothly transitions all properties when the theme switches.
HTML
<body class="ms-theme-dark">
  ...
</body>

Color tokens

Themes redefine the core color custom properties. Components consume them via var(--ms-color-*), so changing the theme updates every component automatically.

TokenPurpose
--ms-color-primaryPrimary brand color
--ms-color-on-primaryText/icon color on primary
--ms-color-secondarySecondary accent color
--ms-color-on-secondaryText/icon color on secondary
--ms-color-surfaceSurface / card background
--ms-color-on-surfaceText color on surfaces
--ms-color-outlineBorders and dividers
--ms-color-errorError / destructive color
--ms-color-successSuccess color
--ms-color-warningWarning color
<