MDUIDocsEnglish简体中文LightDarkSystem
Preset Colors
Custom Color
Extract Color from Wallpaper
Select a Wallpaper
Getting Started
Styles
Frameworks
Components
Functions
JavaScript Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries

getTheme

The getTheme function is used to obtain the current theme applied to the page or a specific element. The available themes are light, dark, and auto. For more information, refer to the Dark Mode section.

Usage

Import the function:

import { getTheme } from 'mdui/functions/getTheme.js';

Example:

// Get the theme on <html>
getTheme();

// Get the theme on an element with class="element"
getTheme('.element');

// Get the theme on a specified DOM element
const element = document.querySelector('.element');
getTheme(element);

API

getTheme(target?: string | HTMLElement | JQ<HTMLElement>): 'light' | 'dark' | 'auto'

This function retrieves the theme of a specified element. The target can be a CSS selector, a DOM element, or a JQ object. If no target is provided, it defaults to the <html> element.

The function returns light, dark, or auto. If no theme is set on the element, it defaults to light.

On this page