Suggestion: Make night mode toggleable in the card type editor

As the title says. Would make designing for both modes a bit more straightforward.

That would be nice. I don’t know if that involves much change in to code. Just to rephrase you point little bit: the idea of having a button in card template editor to toogle the preview windows to a nightmode preview, so not changing the whole Anki IU.

That woud prevent restariing Anki each time for the sole purpose of changing the nightmode on and off in order too see the styling. That scenario would be more useful for the users who do review almost exclusively on mobile versions with nightmode on rather than in the desktop. Just my thought.

1 Like

Thanks for the suggestion, I’ll look into it.

Come to think of it, maybe likewise make the .mobile class toggleable, though that would need an added warning how other factors (different rendering engines, resolution, apps’ own CSS, …) may cause unexpected differences.

a built-in solution sounds useful.


the reddit user /u/yumenogotoshi has posted an add-on (that’s not on ankiweb) that toggles the nightmode in webviews based on a tag, see

source code available at:

in response to a reddit questions of mine here.

in the reviewer you can toggle and reload the webview with my updated version of Tag Toggler (Fork for 2.1)


am i not able to access this or it’s just disabled?

I can access it. I guess it depends on the region and you are in a" US sanctioned region". Here is the code:

from typing import Optional, Any
import anki
import aqt

TARGET_TAG = 'disable_night_mode'
TMP_NORMAL_CLASS = 'tmp_normal_mode'
night_mode_classes = "'nightMode', 'night_mode'"
ADD_NM = f'document.body.classList.add({night_mode_classes});'
REMOVE_NM = f'document.body.classList.remove({night_mode_classes});'
ON_SHOWN = '''
    onShownHook.push(() => {{

def get_normal_mode_window_color():
    ''' Based on: aqt.webview.AnkiWebView._getWindowColor() '''
    qcolor: aqt.qt.QColor
    if anki.utils.isMac:
        # standard palette does not return correct window color on macOS
        qcolor = aqt.qt.QColor('#ececec')
        qcolor =

.{TMP_NORMAL_CLASS} #topbutsOuter {{
    background-color: {get_normal_mode_window_color()};

def toggle_editor_night_mode(tags_text, editor):
    js: str
    if TARGET_TAG in tags_text.split():
        js = REMOVE_NM
        js += f'document.documentElement.classList.add("{TMP_NORMAL_CLASS}");'
        js = ADD_NM
        js += f'document.documentElement.classList.remove("{TMP_NORMAL_CLASS}");'


def on_editor_did_init(editor: aqt.editor.Editor):
        lambda text: toggle_editor_night_mode(text, editor))

def on_webview_will_set_content(
        web_content: aqt.webview.WebContent, context: Optional[Any]):
    if isinstance(context, aqt.editor.Editor):
        web_content.head += f'<style>{EDITOR_TMP_NORMAL_MODE_STYLE}</style>'

def on_card_will_show(text: str, card:, kind: str):
    js_to_append: str
    if TARGET_TAG in card.note().tags:
        js_to_append = ON_SHOWN.format(operation=REMOVE_NM)
        js_to_append = ON_SHOWN.format(operation=ADD_NM)

    return text + js_to_append


Added to