<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="/rss.xsl"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Andrey Listopadov</title>
    <link>https://andreyor.st/tags/css/</link>
    <image>
      <title>Andrey Listopadov</title>
      <link>https://andreyor.st/tags/css/</link>
      <url>https://andreyor.st/tags/css/favicon-64.png</url>
    </image>
    <description>Posts tagged 'css' by Andrey Listopadov</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <copyright>Andrey Listopadov 2020-2026 - This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</copyright>
    <lastBuildDate>Wed, 15 Nov 2023 22:50:00 +0300</lastBuildDate>
    <atom:link href="https://andreyor.st/tags/css/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Why no one uses @media (prefers-color-scheme: dark)?</title>
      <link>https://andreyor.st/posts/2023-11-15-why-no-one-uses-media-prefers-color-scheme-dark/</link>
      <guid>https://andreyor.st/posts/2023-11-15-why-no-one-uses-media-prefers-color-scheme-dark/</guid>
      <description>&lt;p&gt;I don&amp;rsquo;t get it - it&amp;rsquo;s the simplest way to enable dark mode for your website that works across all platforms.
It works on Linux, Android, MacOS, iOS, and maybe even on Windows (I didn&amp;rsquo;t test it, I have no Windows).
I see websites that either use JS to do that or do no dark mode at all.&lt;/p&gt;
&lt;p&gt;Some time ago I started using the &lt;a href=&#34;https://github.com/openstyles/stylus&#34; target=&#34;_blank&#34;&gt;Stylus extension&lt;/a&gt; for Firefox to override CSS for websites that don&amp;rsquo;t do the dark mode.
And you know what?
For a quick fix for most pages, it is as simple as:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-css&#34; data-lang=&#34;css&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;@&lt;span style=&#34;font-weight:bold&#34;&gt;media&lt;/span&gt; (prefers-color-scheme: dark) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    html { &lt;span style=&#34;font-weight:bold&#34;&gt;filter&lt;/span&gt;: &lt;span style=&#34;font-weight:bold;font-style:italic&#34;&gt;invert&lt;/span&gt;(100&lt;span style=&#34;font-weight:bold&#34;&gt;%&lt;/span&gt;) &lt;span style=&#34;font-weight:bold;font-style:italic&#34;&gt;hue-rotate&lt;/span&gt;(180&lt;span style=&#34;font-weight:bold&#34;&gt;deg&lt;/span&gt;); }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    img { &lt;span style=&#34;font-weight:bold&#34;&gt;filter&lt;/span&gt;: &lt;span style=&#34;font-weight:bold;font-style:italic&#34;&gt;invert&lt;/span&gt;(100&lt;span style=&#34;font-weight:bold&#34;&gt;%&lt;/span&gt;) &lt;span style=&#34;font-weight:bold;font-style:italic&#34;&gt;hue-rotate&lt;/span&gt;(180&lt;span style=&#34;font-weight:bold&#34;&gt;deg&lt;/span&gt;); }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Yes, this introduces problems on some pages, for example, embedded videos, especially YouTube ones are hard to invert back.
Images may look horrific if they&amp;rsquo;re done with something else than the &lt;code&gt;img&lt;/code&gt; tag, gradients and colors are preserved but shadows are still inverted, and so on.
But if you have a web page on the web it is you who can do it right, so I don&amp;rsquo;t have to fix it for myself.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-scss&#34; data-lang=&#34;scss&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;font-weight:bold&#34;&gt;@media&lt;/span&gt; (prefers-color-scheme: dark) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  body, textarea { color: #dedddc; background-color: #1e1e1e }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  code { background-color: #2b2b2b; color: #dedddc; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  pre code { background-color: #ddd; color: #333; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  kbd { background-color: #161b22; color: #dedddc; border: solid 1&lt;span style=&#34;font-weight:bold&#34;&gt;px&lt;/span&gt; &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;rgb&lt;/span&gt;(57, 63, 71); border-bottom-color: &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;rgb&lt;/span&gt;(37, 43, 51); }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  tbody tr:nth-child(2n+1) td, tbody tr:nth-child(2n+1) th { background-color: #212121; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  table { border: 1&lt;span style=&#34;font-weight:bold&#34;&gt;px&lt;/span&gt; solid #333; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  td, th { border: 1&lt;span style=&#34;font-weight:bold&#34;&gt;px&lt;/span&gt; solid #333; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.post-list&lt;/span&gt; { h1 a { color: #dedddc; &lt;span style=&#34;font-weight:bold&#34;&gt;&amp;amp;&lt;/span&gt;:hover { color: #7a5fa4; } } }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  a { color: #7a5fa4; &lt;span style=&#34;font-weight:bold&#34;&gt;&amp;amp;&lt;/span&gt;:hover { color: #7a5fa4; } }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  header h2 { a { color: #86868e &lt;span style=&#34;font-weight:bold&#34;&gt;!important&lt;/span&gt;; &lt;span style=&#34;font-weight:bold&#34;&gt;&amp;amp;&lt;/span&gt;:hover { color: #7a5fa4 &lt;span style=&#34;font-weight:bold&#34;&gt;!important&lt;/span&gt;; } &lt;span style=&#34;font-weight:bold&#34;&gt;&amp;amp;&lt;/span&gt;:active { color: #7a5fa4 &lt;span style=&#34;font-weight:bold&#34;&gt;!important&lt;/span&gt;; } } }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  blockquote { border-left: .25&lt;span style=&#34;font-weight:bold&#34;&gt;em&lt;/span&gt; solid #424242; color: #bebebe; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.org-svg&lt;/span&gt; { filter: &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;invert&lt;/span&gt;(90&lt;span style=&#34;font-weight:bold&#34;&gt;%&lt;/span&gt;); }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.invertable&lt;/span&gt; { filter: &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;invert&lt;/span&gt;(100&lt;span style=&#34;font-weight:bold&#34;&gt;%&lt;/span&gt;) &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;hue-rotate&lt;/span&gt;(180&lt;span style=&#34;font-weight:bold&#34;&gt;deg&lt;/span&gt;) &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;contrast&lt;/span&gt;(79&lt;span style=&#34;font-weight:bold&#34;&gt;%&lt;/span&gt;); }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.highlight&lt;/span&gt; { filter: &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;invert&lt;/span&gt;(100&lt;span style=&#34;font-weight:bold&#34;&gt;%&lt;/span&gt;) &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;hue-rotate&lt;/span&gt;(180&lt;span style=&#34;font-weight:bold&#34;&gt;deg&lt;/span&gt;) &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;contrast&lt;/span&gt;(110&lt;span style=&#34;font-weight:bold&#34;&gt;%&lt;/span&gt;); scrollbar-color: #9c9c9c #ddd; background-color: #ddd; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.title-group&lt;/span&gt; { &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.title&lt;/span&gt; { a { color: #dedddc &lt;span style=&#34;font-weight:bold&#34;&gt;!important&lt;/span&gt;; &lt;span style=&#34;font-weight:bold&#34;&gt;&amp;amp;&lt;/span&gt;:hover { color: #7a5fa4 &lt;span style=&#34;font-weight:bold&#34;&gt;!important&lt;/span&gt;; } &lt;span style=&#34;font-weight:bold&#34;&gt;&amp;amp;&lt;/span&gt;:active { color: #7a5fa4 &lt;span style=&#34;font-weight:bold&#34;&gt;!important&lt;/span&gt;; } } } }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  input, input[type=file], button { background-color: #161b22; color: #dedddc; border: solid 1&lt;span style=&#34;font-weight:bold&#34;&gt;px&lt;/span&gt; &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;rgb&lt;/span&gt;(57, 63, 71); }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.diff-added&lt;/span&gt; { background-color: #e2c3da; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#666;font-weight:bold;font-style:italic&#34;&gt;.diff-removed&lt;/span&gt; { background-color: #9fe0d6; }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is all it takes to make dark mode for this page and the rest of the site.
Yes, I use some &lt;code&gt;filter&lt;/code&gt; attributes for specially constructed images and code, and yes, some browsers may not support it, but it generally works well.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;I&amp;rsquo;m bringing this up not because I&amp;rsquo;m some freak who wants dark themes everywhere - no.
My PC switches to the dark theme in the evening automatically to be easier on the eyes with the overall brightness, and when I open some web page it often blinds me with a white background.
Not only it is unpleasant, but it is also bad for your health, as at the end of the day your body is more relaxed, and a sudden flash of light forces your eye muscles to suddenly contract.
It&amp;rsquo;s advised not to look at the screen for several hours before bedtime, but I have a lot of work to do after work, so I can&amp;rsquo;t really afford that.&lt;/p&gt;
&lt;p&gt;I don&amp;rsquo;t browse the web &lt;em&gt;that much&lt;/em&gt;, but have a look at the pages I did adjust because I refer to them fairly often:&lt;/p&gt;
&lt;figure class=&#34;invertable&#34;&gt;&lt;img src=&#34;https://andreyor.st/2023-11-15-why-no-one-uses-media-prefers-color-scheme-dark/fixes.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Most of these are static pages.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Is it that hard to add a single &lt;code&gt;@media (prefers-color-scheme: dark) {...}&lt;/code&gt; block to the style file?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Well, I&amp;rsquo;m not a web developer.
I don&amp;rsquo;t know your ways and such.
You can say that your pages are complicated, your stylesheets are complex and generated with some preprocessor, or you&amp;rsquo;re using some framework that doesn&amp;rsquo;t allow you to do that or whatnot.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ll happily take even the stupid invert filter - as long as it is easy on the eyes I&amp;rsquo;m good.
And yes, there are ways of forcing dark mode on everything, so I guess you can pretend there is no issue here, but it is not true.&lt;/p&gt;
&lt;p&gt;Dark mode makes it easier to read stuff in the dark without causing too much eye fatigue - that&amp;rsquo;s the whole point.
Tone your colors down a bit, bring the contrast down so the light text isn&amp;rsquo;t cutting the eyes against a pure black background and you&amp;rsquo;re good.
And please, don&amp;rsquo;t use JS for that, or at least &lt;a href=&#34;https://stackoverflow.com/a/59621903&#34; target=&#34;_blank&#34;&gt;consult&lt;/a&gt;&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; with the &lt;code&gt;prefers-color-scheme&lt;/code&gt; query, so that your JS code synchronizes with my system-wide preferences.&lt;/p&gt;
&lt;p&gt;Please add dark mode to your static pages.
It&amp;rsquo;s not that hard.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;The stackoverflow was painfully bright at the time of writing this post&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&#34;comment-link&#34;&gt; &lt;a href=&#34;mailto:%61%6e%64%72%65%79%6f%72%73%74%2b%62%6c%6f%67%40%67%6d%61%69%6c%2e%63%6f%6d?subject=Comment: Why no one uses @media (prefers-color-scheme: dark)?&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Comment via email&lt;/a&gt;&lt;/div&gt;</description>
      <pubDate>Wed, 15 Nov 2023 22:50:00 +0300</pubDate>
    </item>
  </channel>
</rss>
