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

前端 未结 5 602
醉酒成梦
醉酒成梦 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:56

    According to Mozilla, here is the preferred method as of 2020

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

    For Safari/Webkit you can use

    @media (prefers-dark-interface) { background: #000; }
    

提交回复
热议问题