• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / User Details / Detect the dark mode

Detect the dark mode

Detect the dark mode

Modern operating systems allow users to choose the appearance they would like to see in all applications.

The option can be detected by looking at the prefers-color-scheme media query.

It can be one of the following values:

  • light: User would like to see the page in the light mode
  • dark: User would like to see the page in the dark mode
  • no-preference: The system doesn’t know about the user preferences

By checking against this media query value, we can determine if the user prefers the dark mode or not:

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

Source

https://htmldom.dev/detect-the-dark-mode/

User Details

Related Snippets:

  • IP Grabber – get a users IP address with JavaScript
  • Detect whether the page is being viewed on a mobile device or a desktop
  • Detect the preferred language of the current user
  • Screen Size

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers