mdn / yari

The platform code behind MDN Web Docs
Mozilla Public License 2.0
1.19k stars 501 forks source link

Examples/Try it inherits the font color from browser prefs #6080

Open 674Y3r opened 2 years ago

674Y3r commented 2 years ago

Summary

If user changes font color in the browser settings, the text in the examples will also change it, but the background will remain white. This can cause contrast issues.

URL

Any page with Examples section, e.g: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meter#examples

Reproduction steps

  1. Go to about:config,
  2. Change the value of;
    • browser.anchor_color to #ff0000,
    • browser.visited_color to #00ff00,
    • browser.display.foreground_color to #ffffff,
    • browser.display.background_color to #000000,
  3. Go to;
  4. See red/lime links and white text on white background.

Expected behavior

Links and text shouldn't change color based on these prefs.

Actual behavior

Links and text change color depending on these prefs.

Device

Desktop

Browser

Firefox

Browser version

Pre-release (e.g. Beta, Nightly or Canary)

Operating system

Linux

Screenshot

Example video with browser.anchor_color. From the first URL.

https://user-images.githubusercontent.com/87250374/165396032-5c76e841-ee8a-427f-a145-6e16229eace4.mp4

Example screenshot with browser.display.foreground_color = #ffffff. Only the selected part of the text is visible. From the second URL.

image

Anything else?

The Try it boxes have a similar problem only with links. Should this be a new bug report?

Validations

caugner commented 2 years ago

@schalkneethling Can you tell if this is a use case that we support from an accessibility point of view?

schalkneethling commented 2 years ago

@schalkneethling Can you tell if this is a use case that we support from an accessibility point of view?

This can help in these situations I believe: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors

Thank you for bringing this issue to our attention @674Y3r.

When setting a background color it is best practice to also set a foreground color and vice versa (in CSS). @674Y3r is it common to only set one of these when using these customization options? Do other websites handle this better? Did the version of MDN Web Docs before the redesign work correctly?

674Y3r commented 2 years ago

When setting a background color it is best practice to also set a foreground color and vice versa (in CSS).

It looks like the iframes have their background color set to white. However, the content inside has a transparent background and foreground color with a value set by the user agent stylesheet to canvasText :thinking: Opening the samples alone works fine. So my guess is that the background set for the iframe is the cause. image

@674Y3r is it common to only set one of these when using these customization options?

I have no idea. Personally I have changed the color of all 4 options available in about:preferences#colors (text, background, unvisited/visited links).

Do other websites handle this better?

Most sites just override this. Although I've had numerous problems with larger/smaller sites that set only the background color or only the foreground color (causing various visibility issues similar to this one). Of course there are a few sites that don't set colors at all, but they are mostly old and very simple.

Did the version of MDN Web Docs before the redesign work correctly?

Sorry, but I don't know if I remember this correctly... I think it worked fine, but I'm not sure.

caugner commented 1 year ago

@674Y3r Could you please verify if the issue persists? I just checked in Firefox with the about:config settings that you provided, and the text of the examples appeared to be readable.

674Y3r commented 1 year ago

Unfortunately, depending on the case, the issue still persists. It is mostly visible with tables. Using https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr#frame_explicitly_specifying_table_content_groups as an example in Firefox Nightly.

Light site theme Dark site theme
Default values (expected) light-default dark-default
Custom values light-custom dark-custom

Default values:

Custom values: