-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauto-dark-mode.css
47 lines (40 loc) · 1.17 KB
/
auto-dark-mode.css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* https://ar.al/2021/08/24/implementing-dark-mode-in-a-handful-of-lines-of-css-with-css-filters/ */
@media (prefers-color-scheme: dark) {
/* Invert all elements on the body while attempting to not alter the hue substantially. */
body {
filter: invert(100%) hue-rotate(180deg);
}
/* Workarounds and optical adjustments. */
/*
Firefox workaround: Set the background colour for the html
element separately because, unlike other browsers, Firefox
doesn't apply the filter to the root element's background.
*/
html {
background-color: #111;
}
/* Do not invert media (revert the invert). */
img, video, iframe, svg {
filter: invert(100%) hue-rotate(180deg);
}
/*
Videos running fullscreen are no longer affected by the
filter on the body so we need to also unset the
revert we applied earlier so we're left with no filter again.
*/
video:fullscreen {
filter: none;
}
/* Improve contrast on icons. */
.icon {
filter: invert(15%) hue-rotate(180deg);
}
/* Re-enable code block backgrounds. */
pre {
filter: invert(6%);
}
/* Improve contrast on list item markers. */
li::marker {
color: #666;
}
}