Page MenuHomePhabricator

.mw-parser-output with inline background styles use light-mode text color causing unreadable text in dark mode
Closed, InvalidPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  1. Go to https://en.wikipedia.org/wiki/User_talk:Martadoulia?safemode=1&useskin=vector-2022&vectornightmode=1 for an example in dark mode.
  2. The SockBlock template from Template:SockBlock is very difficult to read (note the template has a workaround now so the current version won't reproduce the bug).

For a more minimal reproduction, try this example on any English Wikipedia page with dark mode enabled:

{{#invoke:Message box|tmbox|style=background:var(--background-color-warning-subtle);|text=The quick brown fox jumps over the lazy dog.}}

What happens?:

Any element with a style attribute that includes a background value but no explicit color gets a hard-coded light-mode foreground color (#202122).

This comes from here:

https://github.com/wikimedia/mediawiki-extensions-WikimediaMessages/blame/7f938a14f5f639092b2453a51ec038edb601b078/modules/ext.wikimediamessages.styles/theme-night.less#L87

// T358797 - if a background color is specified, assume they wanted the day mode font color
.mw-parser-output [ style*='background' ] {
	/* @color-base */
	color: #202122; // not !important so that if a color is also specified it will take priority
}

This makes text unreadable in dark mode when templates or modules set a background using Codex variables.

What should have happened instead?:

The override should not apply when the background color uses a Codex variable like var(--background-color-warning-subtle). It should also use a more neutral fallback color to minimize the chance of the text being unreadable.

Proposed fix:

.mw-parser-output [style*='background']:not([style*='--background-color']) {
	/* @color-base */
	color: #667755; /* not !important so that if a color is also specified it will take priority */
}
  1. This preserves the intended workaround for inline hard-coded backgrounds but avoids breaking Codex-based ones.
  2. It also uses a fallback color that is readable against most backgrounds in both light and dark modes. While #808080 is a medium gray and would be a reasonable fallback color, #667755 will provide better contrast on more Codex backgrounds. That's based on exploring the color space against each Codex light and dark background (aiming for a minimum 3:1 contrast ratio, which is not ideal, but this is a fallback that is straining to work for both light and dark backgrounds).

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

N/A (English Wikipedia)

Other information (browser name/version, screenshots, etc.):

Tested in Firefox 144.

Event Timeline

Image of the minimal example from above:

Screenshot 2025-11-09 at 13.08.43.png (128×1 px, 29 KB)

Jdlrobson-WMF edited projects, added Vector 2022 (Tracking); removed Vector 2022.
Jdlrobson-WMF subscribed.

This is a generic issue that impacts Minerva skin as well.

It is working as expected and documented on:
https://www.mediawiki.org/wiki/Recommendations_for_night_mode_compatibility_on_Wikimedia_wikis#Always_define_color_when_defining_background
Basically if you use an inline style with background you must also provide the color, otherwise dark mode will assume it is black text.

The correct fix would be to update the page to define a color:

{{Tmbox
| style = background: var(--background-color-destructive-subtle, #fee7e6); color: var( --color-base, inherit );

or

{{Tmbox
| style = background: var(--background-color-destructive-subtle, #fee7e6); color: inherit;

(or request a change to Tmbox to add the inline style where background is detected.

The styles in WikimediaMessages will become obsolete over night, and we will intentionally not be dedicating time or effort to addressing edge cases which can be fixed on wiki.