Saturday, December 7, 2024
HomeSoftware DevelopmentDetect Darkish Mode Desire with JavaScript

Detect Darkish Mode Desire with JavaScript

[ad_1]

Seemingly each web site, dapp, and app affords a darkish mode choice, and thank goodness. Darkish mode is particularly helpful after I’m doing late night time coding, and even worse, buying and selling into altcoins. I am presently engaged on implementing a darkish theme on MetaMask and it obtained me to considering: is there a manner we will default to darkish mode if the consumer’s working system additionally defaults to darkish mode?

You possibly can decide if the consumer’s working system prefers darkish mode with one fast line of code:

const prefersDarkMode = window.matchMedia("(prefers-color-scheme:darkish)").matches; // true

This code snippet takes benefit of the CSS prefers-color-scheme media question with JavaScript’s matchMedia API.

From a consumer expertise standpoint, you will must be cautious in utilizing this snippet. This methodology is nice for setting a default for brand spanking new customers with out altering the worth for present customers.

  • Serving Fonts from CDN

    For max efficiency, everyone knows we should put our belongings on CDN (one other area).  Together with these belongings are customized net fonts.  Sadly customized net fonts through CDN (or any cross-domain font request) do not work in Firefox or Web Explorer (appropriately so, by spec) although…

  • Tips for Starting with Bitcoin and Cryptocurrencies

    One of the rewarding experiences of my life, each financially and logically, has been shopping for and managing cryptocurrencies like Bitcoin, Litecoin, Ethereum. Like studying some other new tech, I made rookie errors alongside the best way, however realized some finest practices alongside the best way. Take a look at…

  • Detect Pseudo-Element Animation Support
  • Shake Things Up Using jQuery UI’s Shake Effect

[ad_2]
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments