Skip to content

[css-pseudo-4] Ensuring selection foreground/background contrast #6150

@chrishtr

Description

@chrishtr

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

Metadata

Metadata

Type

No type

Projects

Status

Wednesday morning

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions