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.

MDUIDocsEnglish简体中文LightDarkSystem
Preset Colors
Custom Color
Extract Color from Wallpaper
Select a Wallpaper
Getting Started
Introduction Installation Usage TypeScript Support IDE Support Localization Frequently Asked Questions
Styles
Dark Theme Dynamic Theme Typography Design Tokens
Frameworks
React Vue Angular
Components
Button ButtonIcon Fab SegmentedButton Chip Card Checkbox Radio Switch Slider RangeSlider List Collapse Tabs Dropdown Menu Select TextField LinearProgress CircularProgress Dialog Divider Avatar Badge Icon Tooltip Snackbar NavigationBar NavigationDrawer NavigationRail BottomAppBar TopAppBar Layout
Functions
JavaScript Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries
@mdui/icons