How to detect if the OS is in dark mode in browsers?

前端 未结 5 597
醉酒成梦
醉酒成梦 2020-11-30 16:53

Similar to \"How to detect if OS X is in dark mode?\" only for browsers.

Has anyone found if there is a way to detect if the user\'s system is in the new OS X Dark M

5条回答
  •  日久生厌
    2020-11-30 17:53

    This is currently (September 2018) being discussed in "CSS Working Group Editor Drafts". Spec has launched (see above), available as a media query. Something has already landed in Safari, see also here. So in theory you can do this in Safari/Webkit:

    @media (prefers-dark-interface) { color: white; background: black }
    

    But it seems that this is private. On MDN a CSS media feature inverted-colors is mentioned. Plug: I blogged about dark mode here.

提交回复
热议问题