Skip to main content
🏠Dark ModeVersion: Next

Dark Mode

Quantum provides a built-in dark theme which can be loaded and dynamically enabled in the browser. The @qtm/tokens package contains the tokens-dark.css to use.

Usage

npm install -S @qtm/tokens@latest
@import '@qtm/tokens/dist/tokens-dark.css';

The dark mode can be enabled by adding the .dark class.

index.html
<!-- Dark mode not enabled -->
<html lang="en">
...
<body>
...
</body>
</html>

<!-- Dark mode enabled -->
<html lang="en" class="dark">
...
<body>
...
</body>
</html>

You can also set the dark mode for a specific section or a component.

<qtm-button color="primary" variant="filled" classes="dark"
>Dark button</qtm-button
>

How to bind the dark mode with the system preferences ?

On page load dark mode can be set with the user system preferences using the media caracteristic (prefers-color-scheme: dark).

// On page load dark mode can be set with the user system preferences
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}