Documentation v8.1.0

Preview Downloads Purchase

Overview

Metronic supports dynamic theme mode switching to both Dark  and Light  modes and storing the user's preference in browser's local storage.

Quick Setup

Change the theme mode by setting data-theme="dark"or data-theme="light"attributes to the page's root <html> tag. Works for background colors, images, text colors, border colors, shadows and even gradients.
<html data-theme="dark">
....
</html>
The theme mode can be set invidivually for particular page blocks despite having different mode for the page:
Instagram Social Media
87%
Instagram Social Media
87%
<!-- Dark mode -->
<div data-theme="dark">
....
</div>

<!-- Light mode -->
<div data-theme="light">
....
</div>

Switch Menu

The theme mode can be switched through unified Theme Mode Switcher opened by the sun or moon icons click in the page's header block. The theme mode switch feature is handled by StudioThemeModejavascript class and allows saving user's preference in the browser's local storage.

Flip Elements

Use .theme-light-showand .theme-dark-showutility classes to flip an element for particular theme mode:
<!-- Show for light mode only-->
<div class="theme-light-show">
....
</div>

<!-- Show for dark mode only-->
<div class="theme-dark-show">
....
</div>

Flip Images

Use .theme-light-showand .theme-dark-showutility classes to flip image for required mode:
<!-- Show for light mode only -->
<img alt="Logo" src="/V2/dist/assets/logos/default.svg" class="theme-light-show h-35px"/>

<!-- Show for dark mode light-->
<img alt="Logo" src="/V2/dist/assets/logos/default-dark.svg" class="theme-dark-show h-35px"/>
Use a custom class defined inside <style>tag for background image flip support:
<!--begin::Image placeholder-->
<style>
 .image-placeholder {
  background-image: url('assets/example.svg');
 }

 [data-theme="dark"] .image-placeholder {
  background-image: url('assets/example-dark.svg');
 }
</style>
<!--end::Image placeholder-->

<!-- Dark and light background image support -->
<div class="image-placeholder">
...
</div>

API Methods

The API methods of StudioThemeModeclass defined in src/js/layout/theme-mode.js:
Name Description
getMode() Returns current theme mode as string
// Returns "dark" or "light" string value.
var mode = StudioThemeMode.getMode();
getMenuMode() Returns the theme switcher menu's current selection mode as string
// Returns "dark", "light" or "system" string value.
var mode = StudioThemeMode.getMenuMode();
getSystemMode() Returns the browser's mode as string
// Returns "dark" or "light" string value.
var mode = StudioThemeMode.getSystemMode();
setMode(String mode) Sets a mode to change the theme mode
StudioThemeMode.setMode("dark");

API Events

The API events of StudioThemeModeclass defined in src/js/layout/theme-mode.js:
Event Type Description
abs.thememode.init This event fires on the theme mode initialization right after the page load.
// Register an event handler
var handlerId = StudioThemeMode.on("abs.thememode.init", function() {
    console.log("Initialized init:" + StudioThemeMode.getMode());
});
abs.thememode.change This event fires on previous navigation button click.
// Register an event handler
var handlerId = StudioThemeMode.on("abs.thememode.change", function() {
    console.log("Theme mode is changed:" + StudioThemeMode.getMode());
});

// Unregister the event handler after 10 seconds
setTimeout(function() {
    StudioThemeMode.off("abs.thememode.change", handlerId);
}, 1000 * 10);

Demos

Metronic Licenses

License FAQs
Regular License
For single end product used by you or one client
$ 39
Extended License
For single SaaS app with paying users
$ 969
Custom License
Reach us for custom license offers.
Buy Now
Learn & Get Inspired

Support at devs.keenthemes.com

Join our developers community to find answer to your question and help others. FAQs
Get Support
Documentation & Videos
From guides and video tutorials, to live demos and code examples to get started.
Plugins & Components
Check out our 300+ in-house components and customized 3rd-party plugins.
Layout Builder
Build your layout, preview it and export the HTML for server side integration.
Metronic Downloads
Download your prefered framework and demo with one click.
What's New
Latest features and improvements added with our users feedback in mind.