โ10-07-2026 07:02 AM
Hello,
I use rich Consoles to print DataFrame modification statistics, and I use dark mode. Up until a few days ago, Databricks handled dark mode by inverting rich's colors. That was fine, I just inverted the colors I wanted before passing them into rich. But Databricks recently changed their dark mode handling such that the colors aren't inverted but they are de-saturated or something. I've tried the recommended class="nodarkmode", but that doesn't completely fix it. For example, in the snippet below, the color bright_red is supposed to "#FF0000", but it is coming out something like "#C56E71". Is there anything else I can try?
from rich.console import Console
import os
import rich
from rich.table import Table
table = Table(style='bright_white on grey0')
table.add_column('ID')
table.add_column('age')
row = ['001', '30']
table.add_row(*row, style='bright_white on bright_red')
record_console = Console(record=True, file=open(os.devnull, 'w'), force_jupyter=False,)
record_console.print(table)
html = record_console.export_html(clear=False)
counter_inverted_html = f"""
<div class="nodarkmode">
{html}
</div>
"""
displayHTML(counter_inverted_html)
โ10-09-2026 06:28 AM
Hello @mksmith521, I took a look at both internal and external documentation and here is what I found.
You're not imagining the change. The notebook appearance docs were updated on October 2 and now describe the new behavior: in dark mode, Databricks flips the light and dark tones of displayHTML output while keeping the original hues. DavidLin (Databricks) confirmed the same on an older Community thread that day. The old behavior was a plain inversion, which is its own inverse, so passing the complement color got you back where you wanted. A tone flip that preserves hue isn't reversible that way, so there's no color you can hand to rich that comes out as #FF0000. Pure red is a fairly dark tone in luminance terms, so the flip lifts and mutes it, and that's roughly what you're seeing. The shift itself is the feature working as designed.
Why nodarkmode isn't fully fixing it is the real question, and I can't see the implementation, so here's how I'd narrow it down. On that older thread, valentin9 found the old dark mode was a CSS filter (invert(1) saturate(0.5)) applied to the output iframe itself. If the new version works the same way, nodarkmode can only counter-correct inside an already-filtered frame, and a close-but-muted red is exactly what an imperfect counter-correction looks like. The other possibility is structural: rich's export_html() defaults to inline_styles=False, so your colors live in a <style> block with generated classes (.r1, .r2) rather than on the spans, and you're nesting a full HTML document inside your div. Either could keep the class from reaching the elements that carry the color.
A two-minute test separates the two. Run this with no rich involved:
displayHTML('<div class="nodarkmode" style="color:#FF0000;background:#000000">bright red test</div>')
If that comes out muted too, nothing you change in rich will fix it. I'd report it through support with this snippet, your cloud, browser and version, and whether the sun icon (below) restores the color. The docs say nodarkmode preserves original colors, so a muted result is a gap between the docs and the behavior.
If the bare div renders true red, the problem is in rich's HTML structure. Inline the styles and emit a fragment instead of a full document:
fragment_template = """<pre class="nodarkmode" style="font-family:Menlo,'DejaVu Sans Mono',monospace;color:{foreground};background-color:{background}"><code style="font-family:inherit">{code}</code></pre>"""
html = record_console.export_html(inline_styles=True, code_format=fragment_template)
displayHTML(html)
Keep the <pre> wrapper so the table's newlines and alignment survive. If the colors still shift, move the class onto the spans instead of the <pre> with html.replace('<span style=', '<span class="nodarkmode" style=').
Two stopgaps while you sort it out. Hover over the output and click the sun icon in the upper-right corner to see that one output in its original colors; it's per output and resets on reload. valentin9 also posted a script that re-inverts the frame when prefers-color-scheme: dark is set, but it was tuned to the old invert(1) saturate(0.5) filter and keys off your OS theme rather than the workspace theme, so I wouldn't expect it to line up with the October change.
References:
nodarkmode๐ https://docs.databricks.com/aws/en/notebooks/notebook-uiexport_html, code_format, inline_styles๐ https://rich.readthedocs.io/en/latest/reference/console.htmlRegards, Louis.
โ10-09-2026 06:28 AM
Hello @mksmith521, I took a look at both internal and external documentation and here is what I found.
You're not imagining the change. The notebook appearance docs were updated on October 2 and now describe the new behavior: in dark mode, Databricks flips the light and dark tones of displayHTML output while keeping the original hues. DavidLin (Databricks) confirmed the same on an older Community thread that day. The old behavior was a plain inversion, which is its own inverse, so passing the complement color got you back where you wanted. A tone flip that preserves hue isn't reversible that way, so there's no color you can hand to rich that comes out as #FF0000. Pure red is a fairly dark tone in luminance terms, so the flip lifts and mutes it, and that's roughly what you're seeing. The shift itself is the feature working as designed.
Why nodarkmode isn't fully fixing it is the real question, and I can't see the implementation, so here's how I'd narrow it down. On that older thread, valentin9 found the old dark mode was a CSS filter (invert(1) saturate(0.5)) applied to the output iframe itself. If the new version works the same way, nodarkmode can only counter-correct inside an already-filtered frame, and a close-but-muted red is exactly what an imperfect counter-correction looks like. The other possibility is structural: rich's export_html() defaults to inline_styles=False, so your colors live in a <style> block with generated classes (.r1, .r2) rather than on the spans, and you're nesting a full HTML document inside your div. Either could keep the class from reaching the elements that carry the color.
A two-minute test separates the two. Run this with no rich involved:
displayHTML('<div class="nodarkmode" style="color:#FF0000;background:#000000">bright red test</div>')
If that comes out muted too, nothing you change in rich will fix it. I'd report it through support with this snippet, your cloud, browser and version, and whether the sun icon (below) restores the color. The docs say nodarkmode preserves original colors, so a muted result is a gap between the docs and the behavior.
If the bare div renders true red, the problem is in rich's HTML structure. Inline the styles and emit a fragment instead of a full document:
fragment_template = """<pre class="nodarkmode" style="font-family:Menlo,'DejaVu Sans Mono',monospace;color:{foreground};background-color:{background}"><code style="font-family:inherit">{code}</code></pre>"""
html = record_console.export_html(inline_styles=True, code_format=fragment_template)
displayHTML(html)
Keep the <pre> wrapper so the table's newlines and alignment survive. If the colors still shift, move the class onto the spans instead of the <pre> with html.replace('<span style=', '<span class="nodarkmode" style=').
Two stopgaps while you sort it out. Hover over the output and click the sun icon in the upper-right corner to see that one output in its original colors; it's per output and resets on reload. valentin9 also posted a script that re-inverts the frame when prefers-color-scheme: dark is set, but it was tuned to the old invert(1) saturate(0.5) filter and keys off your OS theme rather than the workspace theme, so I wouldn't expect it to line up with the October change.
References:
nodarkmode๐ https://docs.databricks.com/aws/en/notebooks/notebook-uiexport_html, code_format, inline_styles๐ https://rich.readthedocs.io/en/latest/reference/console.htmlRegards, Louis.
โ10-12-2026 07:59 AM
Thank you so much @Louis_Frolio! I ran your first code snippet, and the bright red test came out muted red on a black background. Clicking the sun icon restored it to bright red on a black background. paint.net's color picker confirmed the muted color was real, not just a perception issue. I'll see if I can find where to report this to support. Thank you again!
a week ago - last edited a week ago
class="nodarkmode"invert(1) hue-rotate(180deg)
class="nodarkmode"import os
import rich
table = rich.table.Table(style='black on #ffffff')
table.add_column('ID')
table.add_column('age')
row = ['001', '30']
table.add_row(*row, style='black on light_coral')
record_console = rich.console.Console(record=True, file=open(os.devnull, 'w'), force_jupyter=False,)
record_console.print(table)
html = record_console.export_html(clear=False)
displayHTML(html)