Anki has a night mode. It even supports custom CSS rules using the class .night_mode. But there is a better way to do it:
The prefers-color-scheme media query is used to detect if the user has requested a light or dark color theme.
So I request the following feature:
When night mode is enabled prefers-color-scheme: dark should be triggered.
For a demonstration check this out:
In the options section you will see three options: Dark and Light but also an automatic mode which makes use of prefers-color-scheme. When is the system is in dark mode, the css will also load a dark color scheme.
Edit (due to a post merge), this seems to be a bug, not a feature suggestion; as AnkiMobile/AnkiDroid works.
Description
The prefers-color-scheme CSS media query correctly detects light, but fails to detect dark mode on Anki Desktop. When switching Anki’s built-in dark mode, styles using prefers-color-scheme: dark do not apply correctly.
This issue does not occur on AnkiMobile or AnkiDroid.
Steps to Reproduce
Open Anki Desktop (tested on macOS).
Ensure the system theme is set to Light Mode.
Apply the following CSS in the styling section:
@media (prefers-color-scheme: light) {
body {
background: white !important;
color: blue;
}
}
@media (prefers-color-scheme: dark) {
body {
background: black !important;
color: blue;
}
}
The background correctly switches to white in Light Mode.
Now switch Anki Desktop to Dark Mode.
The background remains white instead of switching to black.
Expected Behavior
When Anki Desktop is set to Dark Mode, prefers-color-scheme: dark should return true, and the page should apply dark mode styles (background: black).
Actual Behavior
prefers-color-scheme: lightworks correctly when the system is in Light Mode.
prefers-color-scheme: darkis never detected, even when Anki is switched to Dark Mode.
The background remains white instead of switching to black.
Tested On
OS: macOS 15.3.1
Anki Desktop:
Version: 24.11 (87ccd24e)
Python 3.9.18 / Qt 6.6.2 / PyQt 6.6.1
AnkiDroid:
Version: 2.20.1 (December 23, 2024)
Backend: anki 24.11 / c47638ca
AnkiMobile:
Version: 25.02.2
DevTools Testing:
Manually toggling prefers-color-scheme in Chrome DevTools shows that light is detected, but dark is ignored.
I’m not familiar with Qt, so I’m not sure why our color scheme is not passing down to our webview.
Since Qt 6.5, color scheme detection seems to be supported, so in theme.py, some helper functions could just be replaced, i.e. get_windows_dark_mode(), get_macos_dark_mode(), get_linux_dark_mode()…
QGuiApplication.styleHints().colorScheme() allows us to check the system’s color scheme, but we cannot modify it (until Qt 6.8?)
Constant
Value
Description
Qt::ColorScheme::Unknown
0
The appearance is unknown.
Qt::ColorScheme::Light
1
The background colors are lighter than the text color (Light theme).
Qt::ColorScheme::Dark
2
The background colors are darker than the text color (Dark theme).
In Qt 6.8, we seem to have setColorScheme as a method: