Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript detect dark mode

const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
Comment

detect dark mode javascript

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    console.log(` is dark`);
}else{
  console.log(`shiit is light`);
}
Comment

detect system dark mode javascrip

 const darkTheme = window.matchMedia("(prefers-color-scheme: dark)");
  if (darkTheme.matches) {
       document.documentElement.classList.add("dark");
    } else {
      document.documentElement.classList.remove("dark");
       }
Comment

javascript detect dark mode

const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches

console.log(isDarkMode) // Result: True or False
Comment

PREVIOUS NEXT
Code Example
Javascript :: ajax uploading progress 
Javascript :: find only duplicate data javascript object 
Javascript :: clear localstorage on click jquery 
Javascript :: electron js development auto refresh 
Javascript :: bootstrap modal disable close on click outside react bootstrap 
Javascript :: make select option selected javascript 
Javascript :: react native create view dynamically 
Javascript :: inline style jsx 
Javascript :: javascript check if number is integer 
Javascript :: nuxt head script content 
Javascript :: un hover in jquery 
Javascript :: require is undefined 
Javascript :: nextjs custom document 
Javascript :: in select option how to make one default in angular 
Javascript :: how convert object to string and string to object in javascript 
Javascript :: lodash pascal case 
Javascript :: Unexpected token a in JSON at position 
Javascript :: express async errors 
Javascript :: datatable hide columns 
Javascript :: js int to alphabet 
Javascript :: link script react17 
Javascript :: javascript get a random array from 1 to n 
Javascript :: usenavigate react router dom v6 
Javascript :: javascript wait for multiple promises 
Javascript :: formdata append react js 
Javascript :: push-method-in-react-hooks-usestate 
Javascript :: js sort array of objects 
Javascript :: react how to create range 
Javascript :: vertical align text canvas 
Javascript :: .env file node js 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =