Help us understand the problem. What is going on with this article?

おい、ダークモードには対応していないのか?

「おい、ダークモードには対応していないのか?」と、誰かから言われたり言われなかったり。

で、調べてみたらCSSとJSで良さげなのが見つかったので備忘録代わりに

CSS

@media (prefers-color-scheme: light) {
  /* ライトモード用CSS */
}

@media (prefers-color-scheme: dark) {
  /* ダークモード用CSS */
}

CSSの場合、まだ草案段階なので、ダークモードだけ@mediaを使っていくのが良さげ

対応率も良さげ(低いが、ダークモード対応端末だけで見るとよい割合な気がする。)

C3DFD912-DC34-48D7-B687-1972FDDBEAAA.jpeg
Can I Use

JavaScript

if(window.matchMedia('(prefers-color-scheme: dark)').matches){
  document.write('ダークモードだよ');
} else if (window.matchMedia('(prefers-color-scheme: light)').matches){
  document.write('違うな');
} else {
  document.write('何者だ?');
}

43C8B0D0-196D-4DB4-B437-6A47CDFBF577.jpeg

Can I Use

まとめ

なんか、業界見直したっす

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away