-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pages with color-scheme: dark
have too low link color contrast
#5426
Comments
cc @whatwg/a11y @whatwg/css |
Other colors used in the spec's Rendering section https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3
https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3
https://html.spec.whatwg.org/multipage/rendering.html#tables-2
https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2
https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3
|
I'm a little confused by this issue. Could you provide more background? In particular, does using one of the features mentioned in the OP automatically change the html/body element's background? The links don't go to specs, but instead to issues with problem statements, so I can't really tell. I'm also wondering if this is a general problem whenever authors use CSS/HTML features to change their page's background. Or is it specific to these particular features in some way? |
The spec for this feature is here. I have described
This is only an issue with the default user agent stylesheet rendering, that is, without any author-provided CSS. Note that the demo is completely CSS-free. When an author changes the page background themselves, it's up to them to make sure the contrast is sufficient. |
Sorry, I'm still confused. The spec you link to is for a CSS property and meta tag, so presumably the author must be using a CSS property or meta tag to change the page background? Or no? The demo is completely CSS free, but also does not contain a meta tag, and does not "toggle between dark and light every three seconds" (even on Chrome Canary with experimental web platform features enabled). So I am unsure what it is meant to illustrate. (Edit: I see now that the demo is not completely CSS free after all, but instead is setting an inline |
Correct. But if you say
The demo inserts the CSS property dynamically and toggles its value. There is no other CSS apart from that. In Chrome, you need to switch your OS to dark mode for the demo to have an effect (I have pinged @lilles to see if this is the correct behavior). Again try the demo on Safari; there, it works independent from the OS theme. |
I see. So then I am confused why we would adjust the default rendering of, e.g., links, when the page changes their background using |
The difference is the following: /**
The site supports dark theme. Dear UA stylesheet,
please handle everything I haven't handled. And
since the one rule below is my only CSS, handle it all.
*/
:root {
color-scheme: dark;
} versus: /**
The site supports dark and light theme. Dear UA stylesheet,
please handle everything I haven't handled. And
since I handle link colors, handle everything else.
*/
:root {
color-scheme: dark light;
}
a {
/* I know what I'm doing, I mess with the default styling */
color: white;
background-color: black;
}
@media (prefers-color-scheme: dark) {
a {
/* I know what I'm doing, I mess with the default styling */
color: black;
background-color: white;
}
} |
Yes, switching on the color scheme is assumed to switch all the "default" coloring as well. The When the UA flips into dark mode, the default background and text color change, as do the colors of inputs. Links should follow along, as should any other default colors applied by the UA stylesheet. Two reasonable ways to approach this. The first, and simplest, is to switch as much of these colors as possible to using the allowed system color keywords, which work not only with light/dark mode, but with forced-colors mode as well. As long as these keywords are only used in the properties with special resolved-value behavior, then it shouldn't even be a detectable change; calling The second way is to explicitly add an If there are properties not on the resolved-values list, we can do option 2 for just those, and rely on option 1 for the rest for simplicity; or we could do option 2 for everything for consistency. I have no opinion on the matter. |
To me, Option 1 sounds like the more consistent and more scalable approach; more scalable especially given the other color adjustments |
Ideally that would have been done as part of standardizing cc @smfr |
For For Chrome with manually injected It's early days for Safari with manually injected Firefox (doesn't support |
Yes, if we need to we can add more system colors; if they're needed just to express the default UA visual semantics, that's a good argument for their inclusion. But also you can just use the MQ to manually address those particular color needs explicitly, and use the system colors for everything else for simplicity. |
(I read this as concerning developer-provided CSS, not as using the MQ in the user-agent stylesheet.) If the out-of-the box user-agent stylesheet experience is not accessible, I don't think this can be the solution. No question, most developers will override the default look and feel and have link colors that are on-brand etc., but also some won't. Prominent timely example: http://lite.cnn.com/en (you can see all their CSS in the screenshot, I have inserted the meta tag manually): |
No, Tab meant in the UA stylesheet. I do think that if we were to switch to system colors their light/dark defaults would have to be written down somewhere. |
Gotcha, I wasn't 100% sure, so I added my (wrong) interpretation. In that case, sure, MQing in the UA stylesheet is an option, following the nomenclature from above, that'd be Option 2. Personally, I still prefer Option 1.
+1. |
You mean if we start using LinkText, VisitedText, ActiveText in the UA sheet we need to spec the exact RGBA values for both light and dark versions, e.g. in CSS Color? Wrt @media queries in the UA stylesheet, that won't work since the media query depends on the preferred color-scheme and the UA colors could be different for different elements in the same document since the color-scheme property has a per element computed and used value. If the preferred color scheme is dark, the two links below would be rendered with different colors (with system colors in the UA sheet):
But this UA sheet would end up with orange for both:
|
@lilles yeah, exactly. I guess it's an existing problem that it's not defined what It sounds like CSS needs to define system colors for all the different colors used in HTML's Rendering section and define their default values for various color schemes. |
just wanted to check...am i missing something fundamental? if i have a vanilla HTML document with no styling defined, load it in Chrome, and switch (on Windows) between light/dark app mode, I see Chrome's UI change, but the vanilla page itself does not change at all (using Chrome 80) and to clarify, i know that i as an author can then go in and make [edit: ah, seems i got the wrong end of the stick here ... so this is explicitly about when the page opts into dark mode via the meta, rather than adapting to user preference?] |
@patrickhlauke To quickly test this, go to https://lite.cnn.com/en, then paste the snippet below in the console: |
Yup, backwards compat constrains what we can do by default; too many pages are authored with the assumption of a white background or black text, and would become unreadable if swapped to a dark background or light text. By default, the only result of your OS being in dark mode is that the To opt your page into UA-provided dark-mode colors, the |
yeah, sorry for coming in sideways there...took me a few re-reads, but i get it now and agree. |
w3c/csswg-drafts#4924 now has introduced more system color keywords. |
Are defaults defined for various color schemes? (Doesn't look like it, so this isn't unblocked yet.) |
Not yet, @fantasai and I ran out of time to address that in our last working day. We'll get to it soon. |
Came across this while looking into dark mode support for Geary, which uses WebKit to render email bodies. Using And now I must choose a link color for readability. Ideally, though, Geary could simply use Aside from Geary, I also think this is a moderately important feature for the web. So this is a friendly bump! |
It looks like the remaining work here is:
|
Following whatwg/html#5426, it looks like the Chrome team have decided that this is reasonable
…re. r=dholbert For that, add `.dark` version of the browser.display* prefs that control the light version of these colors. The default for background/foreground colors are taken from the GenericDarkColors used in LookAndFeel. The defaults for links are based on this discussion: whatwg/html#5426 (comment) (So they effectively match Chrome). Whether the dark colors should be exposed in about:preferences (like the light colors are) is TBD. With this patch, we pass all the tests in: /html/semantics/document-metadata/the-meta-element/color-scheme/ Use the colors to paint the default canvas background and the default colors. There are three "regressions", though they are really progressions: we now render the reference as the test expects (before we rendered a light canvas background even for the reference). Apart of these iframe tests (which we should look into, I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1738380), there are three remaining test failures. Two of them are due to `color: initial` not changing based on the color-scheme. Safari also fails these tests, and the thing they're really testing is whether system colors are preserved at computed-value time: w3c/csswg-drafts#3847 Regarding that change, I'm not so sure the trade-offs there are worth it, as that not only complicates interpolation (we wouldn't be able to use system colors in color-mix among others, see w3c/csswg-drafts#5780) plus it changes inheritance behavior in sorta unexpected ways, see: w3c/csswg-drafts#6773 Which I just filed because apparently no browser implements this correctly. So for now will punt on those (keep matching Safari). There's an svg-as-image test: https://searchfox.org/mozilla-central/rev/f8576fec48d866c5f988baaf1fa8d2f8cce2a82f/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html Which isn't using the feature at all and I'm not sure why is it supposed to pass (why prefers-color-scheme: dark is supposed to match that SVG image). This test fails in all browsers apparently: https://wpt.fyi/results/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html?label=master&label=experimental&aligned I sent web-platform-tests/wpt#31407 to remove it and hopefully get it reviewed by some Chromium folks. Differential Revision: https://phabricator.services.mozilla.com/D129746
…re. r=dholbert For that, add `.dark` version of the browser.display* prefs that control the light version of these colors. The default for background/foreground colors are taken from the GenericDarkColors used in LookAndFeel. The defaults for links are based on this discussion: whatwg/html#5426 (comment) (So they effectively match Chrome). Whether the dark colors should be exposed in about:preferences (like the light colors are) is TBD. With this patch, we pass all the tests in: /html/semantics/document-metadata/the-meta-element/color-scheme/ Use the colors to paint the default canvas background and the default colors. There are three "regressions", though they are really progressions: we now render the reference as the test expects (before we rendered a light canvas background even for the reference). Apart of these iframe tests (which we should look into, I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1738380), there are three remaining test failures. Two of them are due to `color: initial` not changing based on the color-scheme. Safari also fails these tests, and the thing they're really testing is whether system colors are preserved at computed-value time: w3c/csswg-drafts#3847 Regarding that change, I'm not so sure the trade-offs there are worth it, as that not only complicates interpolation (we wouldn't be able to use system colors in color-mix among others, see w3c/csswg-drafts#5780) plus it changes inheritance behavior in sorta unexpected ways, see: w3c/csswg-drafts#6773 Which I just filed because apparently no browser implements this correctly. So for now will punt on those (keep matching Safari). There's an svg-as-image test: https://searchfox.org/mozilla-central/rev/f8576fec48d866c5f988baaf1fa8d2f8cce2a82f/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html Which isn't using the feature at all and I'm not sure why is it supposed to pass (why prefers-color-scheme: dark is supposed to match that SVG image). This test fails in all browsers apparently: https://wpt.fyi/results/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html?label=master&label=experimental&aligned I sent web-platform-tests/wpt#31407 to remove it and hopefully get it reviewed by some Chromium folks. Differential Revision: https://phabricator.services.mozilla.com/D129746
Colors in the blue-purple-red range (esp. blue) generally appear darker to the human eye, which is exacerbated by many common forms of color deficiencies. Blue text is a good fit for light backgrounds, but not dark backgrounds. Colors in the orange-yellow-green range (esp. yellow) generally appear lighter; they work well against a dark background. The above observations are reflected by the (experimental) Advanced Perceptual Contrast Algorithm, which can be enabled in Chromium's devtools's "Experiments" settings window. I think that it might be worth experimenting with making the orange-yellow-green range the norm for colored foreground text in dark modes, including browser default stylesheets. There's still time before these are set in stone. |
Yeah there are especially problems with purple, very very weak on dark backgrounds. I run into that all the time and often have to deviate from the rest/neutral, hover/brighter, active/darker schema when I use purple. Although yellow definitely provides way better contrast with the background, it's much less recognizable, much less associated with hyperlinks. I don't think contrast with the background is really the main issue. Any hue can have sufficient contrast with dark gray if you adjust the lightness to compensate for the well-known asymmetries in human color perception. I was just reading an interesting article about this exact subject last week. I had always thought the blue tradition was because of Tim Berners-Lee but apparently he originally used green. Which seems so strange to me, but I still find red kind of awkward, so maybe it's just a personal prejudice. The only colors I've ever used generically for hyperlinks are variations of blue. And hues close enough to be called blue, the extreme ends of which I'd estimate at #9999ff to #99ffff. I don't think variations in color vision have much bearing on the choice of rest hue, because with hyperlinks hue differentiation isn't that important, except insofar as a link needs to be distinguishable from ordinary white or black text to be perceived as a link. And by that metric, yellow is the worst because it's the hardest to distinguish from white, which will usually be the base text color for a dark scheme, whereas indigo would be the easiest. I don't think that rules yellow out but just worth noting. Differentiating red from green may be important in buttons where you use them to distinguish a negative from an affirmative, but in links it's mainly just important to distinguish it from black/white. The visited and active states should have sufficient contrast with the rest state obviously, but that can be achieved irrespective of where you start the scheme. This looks good to me and works with the most common color vision variations: Idk if this is quite what you had in mind, but it was the least gaudy scheme I could come up, with the premise of using yellow as the base and achieving higher contrast than the above scheme. Yellow, orange, and green don't have optimal contrast with each other, so I did yellow, red, blue. Which does have better contrast but looks so bad to me. Maybe it's just me, but yellow is among my least favorite colors for design, especially where more than 2 major hues are called for. But where yellow is obligatory, it pains me not to use blue with it. In any case, this color scheme just feels kinda "halloweeny" for me. Blue has its issues, but it's clean, it evokes the sky, it's the color of inspiration, and simultaneously an extremely neutral color. So it seems better as a rest color than yellow, which seems to have connotations of "warning" or "highlight" at least in western culture. Definitely a subject worth researching though. The same could be said for red, (and red is my least favorite part of the above scheme) but that's probably fine as long as it's not the rest color. If this scheme below evokes anything else for me, it's... peanut butter cups? |
On Wed, Dec 29, 2021 at 01:26:08AM -0800, aminomancer wrote:
Maybe it's just me, but yellow is among my least favorite colors for design, especially where more than 2 major hues are called for.
I would agree, but yellow accents on black tend to look great. Black(ish) backgrounds change lots of the rules.
But where yellow is obligatory, it pains me not to use blue with it. In any case, this color scheme just feels kinda "halloweeny" for me. Blue has its issues, but it's clean, it evokes the sky, it's the color of inspiration, and simultaneously an extremely neutral color.
Blue is *great*...for light backgrounds. To the human eye, blue is a dark color; on a black background, blue needs to be *very* light to have good perceptual contrast.
When it's dark, we turn on artificial lights and many screens automatically adjust gamma levels at night (c.f. "night color" and "night light" OS features and software like redshift/gammastep). Yellowish/orangish hues are the norm in the dark.
If this scheme below evokes anything else for me, it's... peanut butter cups? <img src="https://user-images.githubusercontent.com/33384265/147645737-180532a9-98c0-45ce-be7d-3e94bf1ed3f5.png" height="500"/>
I use a yellow base on my site, https://seirdy.one/. I don't use a completely different hue for visited text: I use nearly-white yellow for visited links to mimic the effect of "almost the same color as text" that I saw with purple links. It should have good APCA values, with the exception of superscripts/subscripts.
Another example might be https://whalecoiner.com by @whalecoiner. This also passes the APCA for normal font sizes. Unlike my site, this uses many different hues.
I think that whalecoiner got it down pretty well, though I might swap out green with whitish yellow for visited links; that'd look more "de-emphasized" since the color would blend in with regular text.
…--
/Seirdy
|
The base link color on your site is a good tone for yellow, but the nearly-white yellow active state is indistinguishable from the text color. That might be fine for an individual website but it's probably not gonna become a web standard. At that lightness it's also less distinct than chromium's (and now firefox's) light indigo. The whalecoiner scheme is similar to the color scheme I tested, but it lacks an active state, apparently in lieu of a subtle hover state. The difficulty of adding a third color is the biggest problem with this scheme. The green visited state looks terrible to me, but swapping it out for near-white would make the scheme really deficient in state contrast. That is, base color is peach, active color is peach, visited color would be practically indistinguishable from regular text. By the way, I also think there's something to be said for the dark color scheme corresponding (at least somewhat) to the light color scheme. It's true that perceptual contrast for hues essentially reverses with the background lightness, so there is an argument for reversing the hues. But most people won't notice the color complementarity as a correspondence. It's such an extreme flip, and such an extreme break with tradition. Most browsers treat blue as a sort of base accent color, to be used in both the chrome and UA styles. And most websites built in the last 20+ years have been built with the expectation that hyperlinks will be blue. So not only are there gonna be websites that never overrode the anchor element UA styles, but many websites will have integrated that expectation into their design. Very few websites even use color-scheme at present so it would be quite a burden supporting not only a dark and a light mode, but a blue and a yellow mode as well. Whereas the chromium colors only break slightly from tradition and they don't clash with the more solid traditional colors. |
yo! anything that I did on that site was so hella rushed it was unreal, but thank you! (hi to familiar names on this thread - long time no see since abandoning the twitters) |
Hello everyone — I will try to be as succinct as possible, I will say that @Seirdy is providing solid information and good examples. WCAG 2 and Dark ModeWCAG 2 provides meaningless values for a black background. In fact, when both colors are darker than about #999, WCAG2 contrast has no real utility. I recently published an article on this, here's a link that bypasses the paywall so you can read it for free: atangledwebweweave.com/whats-red-black-also-not-read APCA Does Dark ModeIf designing for dark mode, APCA gives useful contrast guidance. The current canonical tool is: myndex.com/APCA/ Bridge-PCA for WCAG 2 Backwards CompatibilityBecause of concerns over backwards compatibility, I released Bridge-PCA. It's backwards compatible with WCAG 2 contrast, but using APCA technology. "It fixes dark mode when used as directed". There's a simple demonstrator at myndex.com/BPCA/ Both are available as npm packages:
Both are open-source for use with web content. Topsy Turvey ColorsBlue has very little luminance. The eye's S cone (blue) does not contribute to luminance (it can subtract). Plus, there are no blue cones in the central foveal area, and they are sparsely scattered in the periphery, so they contribute nothing to detail — so you just can not use a pure primary blue on black. And the same goes for pure reds. Direct ComparisonThis chart shows WCAG 2 degrading contrast as colors become darker. APCA maintains readability across the visible range. Any questions or comments are welcome here or at the APCA repo. Thank you, Andy |
I am coming across this now - I've found that chrome on Android renders links in dark mode with just enough contrast, but if I want to use that same color elsewhere and have it change automatically with color-scheme, I cannot, as it appears to be different from LinkText I've tweeted some examples, the code and my frustration here: https://twitter.com/sarajwallen/status/1523967142789451776 |
For that, add `.dark` version of the browser.display* prefs that control the light version of these colors. The default for background/foreground colors are taken from the GenericDarkColors used in LookAndFeel. The defaults for links are based on this discussion: whatwg/html#5426 (comment) (So they effectively match Chrome). Whether the dark colors should be exposed in about:preferences (like the light colors are) is TBD. With this patch, we pass all the tests in: /html/semantics/document-metadata/the-meta-element/color-scheme/ Use the colors to paint the default canvas background and the default colors. There are three "regressions", though they are really progressions: we now render the reference as the test expects (before we rendered a light canvas background even for the reference). Apart of these iframe tests (which we should look into, I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1738380), there are three remaining test failures. Two of them are due to `color: initial` not changing based on the color-scheme. Safari also fails these tests, and the thing they're really testing is whether system colors are preserved at computed-value time: w3c/csswg-drafts#3847 Regarding that change, I'm not so sure the trade-offs there are worth it, as that not only complicates interpolation (we wouldn't be able to use system colors in color-mix among others, see w3c/csswg-drafts#5780) plus it changes inheritance behavior in sorta unexpected ways, see: w3c/csswg-drafts#6773 Which I just filed because apparently no browser implements this correctly. So for now will punt on those (keep matching Safari). There's an svg-as-image test: https://searchfox.org/mozilla-central/rev/f8576fec48d866c5f988baaf1fa8d2f8cce2a82f/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html Which isn't using the feature at all and I'm not sure why is it supposed to pass (why prefers-color-scheme: dark is supposed to match that SVG image). This test fails in all browsers apparently: https://wpt.fyi/results/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html?label=master&label=experimental&aligned I sent web-platform-tests/wpt#31407 to remove it and hopefully get it reviewed by some Chromium folks. Differential Revision: https://phabricator.services.mozilla.com/D129746
For that, add `.dark` version of the browser.display* prefs that control the light version of these colors. The default for background/foreground colors are taken from the GenericDarkColors used in LookAndFeel. The defaults for links are based on this discussion: whatwg/html#5426 (comment) (So they effectively match Chrome). Whether the dark colors should be exposed in about:preferences (like the light colors are) is TBD. With this patch, we pass all the tests in: /html/semantics/document-metadata/the-meta-element/color-scheme/ Use the colors to paint the default canvas background and the default colors. There are three "regressions", though they are really progressions: we now render the reference as the test expects (before we rendered a light canvas background even for the reference). Apart of these iframe tests (which we should look into, I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1738380), there are three remaining test failures. Two of them are due to `color: initial` not changing based on the color-scheme. Safari also fails these tests, and the thing they're really testing is whether system colors are preserved at computed-value time: w3c/csswg-drafts#3847 Regarding that change, I'm not so sure the trade-offs there are worth it, as that not only complicates interpolation (we wouldn't be able to use system colors in color-mix among others, see w3c/csswg-drafts#5780) plus it changes inheritance behavior in sorta unexpected ways, see: w3c/csswg-drafts#6773 Which I just filed because apparently no browser implements this correctly. So for now will punt on those (keep matching Safari). There's an svg-as-image test: https://searchfox.org/mozilla-central/rev/f8576fec48d866c5f988baaf1fa8d2f8cce2a82f/testing/web-platform/tests/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html Which isn't using the feature at all and I'm not sure why is it supposed to pass (why prefers-color-scheme: dark is supposed to match that SVG image). This test fails in all browsers apparently: https://wpt.fyi/results/css/css-color-adjust/rendering/dark-color-scheme/svg-as-image.html?label=master&label=experimental&aligned I sent web-platform-tests/wpt#31407 to remove it and hopefully get it reviewed by some Chromium folks. Differential Revision: https://phabricator.services.mozilla.com/D129746
Now that the standardized
<meta name="color-scheme">
and the corresponding CSS propertycolor-scheme
have landed in Chrome and Safari, an accessibility issue around link colors occurs:The colors defined in §14.3.4 Phrasing content…
…do not have sufficient contrast on a dark background. See this demo (note the [Top] links):
This issue should probably also affect the definition of the CSS System Colors:
LinkText
(contrast insufficient): Text in non-active, non-visited links.VisitedText
(contrast insufficient): Text in visited links.ActiveText
(contrast OK-ish): Text in active links.I have also opened bugs for Chrome, WebKit, and Firefox for awareness and to get this fixed.
The text was updated successfully, but these errors were encountered: