[css-pseudo-4] Ensuring selection foreground/background contrast · Issue #6150 · w3c/csswg-drafts (original) (raw)

The ::selection pseudo-element allows the developer to change the foreground and background of a selection.

What happens if there is not good enough contrast between the selected colors? Webkit and Chromium (*) currently have code that inverts the background, if the background and foreground color are exactly
the same. Gecko does not have this logic. Here is an example page that differs.

Should we view this as a website bug, or an opportunity for the UA to intervene and ensure contrast? One argument for the latter could be that selection is primarily a UA feature, and therefore it's appropriate to intervene to override site bugs. But if we do so, any difference in heuristics between browsers could result in (probably accidentally) broken sites in some browsers.

Finally, the same question could be asked about the various other pseudo elements that are similar to selection.

(*) Webkit code link
Chromium code link
Gecko bug tracking an interop issue caused by this