Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  4] [ 6]  / answers: 1 / hits: 22246  / 4 Years ago, mon, july 20, 2020, 12:00:00

Dark/Light mode toggle settings on websites and app are tredning and there is a some system default theme mode also available like chrome dev-tools provide force dark-mode, but I want my website to be view in the way it has been built. So, How do I prevent the force dark-mode, applied by chrome?


I have tried prefers-color-scheme media query, but I guess, I'm doing something wrong or missing something.


@media (prefers-color-scheme: dark) {
body {
background: #fff;
}
}

More From » css

 Answers
2

Google has released an article explaining different methods for enabling forced dark mode, and strategies to handle them both by JavaScript and CSS.


https://developer.chrome.com/blog/auto-dark-theme/#detecting-auto-dark-theme


By forcing dark mode in Chrome you can do dark mode detection, and they have included an opt-out CSS property.


:root {
color-scheme: only light;
}

Or on specific items:


#my-onlylight-element {
color-scheme: only light;
}

This is seemingly also supported by Safari (Chrome information in this table is outdated, bug has been reported on that):
https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme


[#50781] Monday, July 13, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byronkodyo

Total Points: 552
Total Questions: 87
Total Answers: 104

Location: Burundi
Member since Sat, Aug 21, 2021
3 Years ago
byronkodyo questions
Wed, Jul 6, 22, 00:00, 2 Years ago
Wed, Mar 17, 21, 00:00, 3 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
;