Steps to replicate the issue (include links if applicable):
- Go to https://en.wikipedia.org/wiki/User_talk:Martadoulia?safemode=1&useskin=vector-2022&vectornightmode=1 for an example in dark mode.
- 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:
// 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 */
}- This preserves the intended workaround for inline hard-coded backgrounds but avoids breaking Codex-based ones.
- 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.
