Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

detect system dark mode tailwind css

// toggle  
const darkTheme = window.matchMedia("(prefers-color-scheme: dark)");
  if (darkTheme.matches) {
       document.documentElement.classList.add("dark");
    } else {
      document.documentElement.classList.remove("dark");
       }
Source by tailwindcss.com #
 
PREVIOUS NEXT
Tagged: #detect #system #dark #mode #tailwind #css
ADD COMMENT
Topic
Name
2+3 =