# Selecting Night Mode should trigger \`prefers-color-scheme: dark\` so relevant CSS rules are applied

**URL:** <https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147>\
**Category:** Suggestions\
**Created:** [October 14, 2021, 6:28pm UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147 "2021-10-14T18:28:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![chromian](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/chromian/32/6802_2.png) [@chromian](https://forums.ankiweb.net/u/chromian)\
**Post date:** [October 14, 2021, 6:28pm UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/1 "2021-10-14T18:28:30Z")

</div>

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](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/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:

> **[Water.css](https://watercss.kognise.dev/)**
>
> A drop-in collection of CSS styles to make simple websites like this just a little bit nicer.

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.

---

<div class="post-metadata">

**Author:** ![BartL](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@BartL](https://forums.ankiweb.net/u/BartL)\
**Post date:** [December 8, 2024, 6:06pm UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/2 "2024-12-08T18:06:41Z")

</div>

This is still relevant. As a test, this should work out of the box:

```css
p {
 color: red;
}

@media (prefers-color-scheme: dark) {
  p {
   color: blue;
  }
}

```

---

<div class="post-metadata">

**Author:** ![BartL](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@BartL](https://forums.ankiweb.net/u/BartL)\
**Post date:** [December 8, 2024, 6:42pm UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/3 "2024-12-08T18:42:52Z")

</div>

I checked and couldn’t find a way to set prefers-color-scheme with QWebEngine. [PySide6.QtWebEngineCore.QWebEngineSettings - Qt for Python](https://doc.qt.io/qtforpython-6/PySide6/QtWebEngineCore/QWebEngineSettings.html#PySide6.QtWebEngineCore.QWebEngineSettings)

---

<div class="post-metadata">

**Author:** ![louis15](https://avatars.discourse-cdn.com/v4/letter/l/c5a1d2/32.png) [@louis15](https://forums.ankiweb.net/u/louis15)\
**Post date:** [February 14, 2025, 3:35am UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/4 "2025-02-14T03:35:30Z")

</div>

I’ll second this, with prefers-color-scheme working, we can define color like this

```css
:root {
  color-scheme: light dark;
}

p {
  light-dark(red, blue);
}

```

This is much much more efficent, and already work on ankidroid.

Since prefers-color-scheme is widely available on all modern browser now, this maybe eay to set.

---

<div class="post-metadata">

**Author:** ![tyuichis](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tyuichis](https://forums.ankiweb.net/u/tyuichis)\
**Post date:** [March 14, 2025, 11:18pm UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/5 "2025-03-14T23:18:11Z")

</div>

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**

1. Open **Anki Desktop** (tested on macOS).

2. Ensure the **system theme is set to Light Mode**.

3. Apply the following CSS in the styling section:

4. The background correctly switches to **white** in Light Mode.

5. Now switch **Anki Desktop to Dark Mode**.

6. 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: light` **works correctly** when the system is in Light Mode.
- `prefers-color-scheme: dark` **is 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:**

- **AnkiDroid:**

- **AnkiMobile:**

- **DevTools Testing:**

* * *

### **Additional Notes**

- This issue **only occurs on Anki Desktop**.

- Running this JavaScript test:

* * *

### **Possible Causes & Debugging**

- This may be related to how Anki applies `.night-mode` styling.
- A possible fix could be ensuring that Anki’s dark mode also updates the system’s reported theme preference

---

<div class="post-metadata">

**Author:** ![Anon\_0000](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Anon\_0000](https://forums.ankiweb.net/u/Anon_0000)\
**Post date:** [March 14, 2025, 11:41pm UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/6 "2025-03-14T23:41:41Z")

</div>

**Edit:** Now irrelevant because Danika\_Dakika merged the two topics.

---

<div class="post-metadata">

**Author:** ![tyuichis](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tyuichis](https://forums.ankiweb.net/u/tyuichis)\
**Post date:** [March 15, 2025, 12:41am UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/7 "2025-03-15T00:41:58Z")

</div>

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). |

> **[QStyleHints Class | Qt GUI 6.8.2](https://doc.qt.io/qt-6.5/qstylehints.html#colorScheme-prop)**
>
> The QStyleHints class contains platform specific hints and settings.

In Qt 6.8, we seem to have `setColorScheme` as a method:

> **[QStyleHints Class | Qt GUI 6.8.2](https://doc.qt.io/qt-6.8/qstylehints.html#colorScheme-prop)**
>
> The QStyleHints class contains platform specific hints and settings.

---

<div class="post-metadata">

**Author:** ![sorata](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/sorata/32/34115_2.png) [@sorata](https://forums.ankiweb.net/u/sorata)\
**Post date:** [March 15, 2025, 7:04am UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/8 "2025-03-15T07:04:47Z")

</div>

I think BartL (the person above) made some changes in December. Is this an issue with Anki desktop 25.02 version? I see you only tested on 24.11 ver.

---

<div class="post-metadata">

**Author:** ![tyuichis](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tyuichis](https://forums.ankiweb.net/u/tyuichis)\
**Post date:** [March 15, 2025, 8:42am UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/9 "2025-03-15T08:42:57Z")

</div>

Thanks for the heads-up. I updated to 25.02 – issue still persists.

console.log("dark-theme: ", window.matchMedia(‘(prefers-color-scheme: dark)’).matches);  
console.log("light-theme: ", window.matchMedia(‘(prefers-color-scheme: light)’).matches);

Same results.

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [March 16, 2025, 3:30pm UTC](https://forums.ankiweb.net/t/selecting-night-mode-should-trigger-prefers-color-scheme-dark-so-relevant-css-rules-are-applied/14147/10 "2025-03-16T15:30:05Z")

</div>

This should be fixed in Qt 6.7 according to [[Qt 6.7] Set ForceDarkMode attribute in AnkiWebView by louwers · Pull Request #3622 · ankitects/anki · GitHub](https://github.com/ankitects/anki/pull/3622)

Anki is still on Qt 6.6 due to regressions in recent releases: [Revert "Qt 6.8.1" · ankitects/anki@cd18241 · GitHub](https://github.com/ankitects/anki/commit/cd1824165ffb0ba06f573e1e26f28078a35d93a9)
