Open felipeerias opened 4 years ago
One starting point to approach this, just to get the ball rolling, could be to use the provided color for the thumb and calculate the track color by keeping the same hue and changing lightness/saturation automatically until the desired contrast is found.
In the first example above, the thumb would be #FFA500
and the track would perhaps be #362B17
(using this contrast checker as reference).
In the second, the thumb would be #006400
and the track would perhaps be #E5ffE5
(reference).
This approach might not work in all cases, for instance with the crimson
color #DC143C
. For those cases, maybe the thumb color would need to be changed slightly to increase the contrast with the background. For example, scrollbar-color: crimson;
might produce a #9e0e2b
thumb and a #fae9ed
track (reference).
This is separate, yet quite strongly related to the issues about accent color: https://github.com/w3c/csswg-drafts/issues/5187 / https://github.com/w3c/csswg-drafts/issues/5480 / https://github.com/w3c/csswg-drafts/issues/5544 / https://github.com/w3c/csswg-drafts/issues/5577
I don't know if this has been discussed previously, but what should happen if only one color was provided to
scrollbar-color
?
What we recommended was slightly different: that each of the two color values also accepts the value auto
, which produces a color generated by the UA. Then a single <color>
value can just be a shorter form of <color> auto
or auto <color>
, whichever is more useful.
One starting point to approach this, just to get the ball rolling, could be to use the provided color for the thumb and calculate the track color by keeping the same hue and changing lightness/saturation automatically until the desired contrast is found.
On a high level, yes. However, as with most things color, this is not as simple and straightforward as it sounds:
hsl(20, 100%, 30%)
(brown) by 50% produces hsl(20, 100%, 45%)
(orange). Mixing with white or black, even if the interpolation is done in HSL, can produce better results (e.g. hsl(20, 50%, 65%)
, a light brown).Footnote: Link to calculations
Thank you very much for your detailed feedback, @LeaVerou
I thought that there could be a way to define what would happen if only one color was provided to scrollbar-color
, but it seems that this syntax is too ambiguous to provide a good outcome in all cases.
I like your proposal to use a keyword to indicate that a part's color should be automatically calculated by the UA. Do you want to open a separate issue for that?
I don't think we should get into the details of specifying exactly how the browser computes the contrasting color. It should just do so, in a way that ensure good contrast, and how to do that is up to the UA.
Also, do we want: auto | <color> {1,2}
or [auto | <color>]{1,2}
? With the latter, when providing a single color, you can decide if it's for the track or the thumb, while with the first one, you just give a tint and let the UA worry about where it goes.
The CSS Working Group just discussed single-color scrollbar-color
, and agreed to the following:
RESOLVED: Defer to L2
The property scrollbar-color from CSS Scrollbars allows the author to pass two colors, to be used by the thumb and the track of the scrollbar.
So,
scrollbar-color: indigo lavender
will produce a scrollbar where the thumb is#4B0082
and the track is#E6E6FA
.The spec also advises authors to "ensure the specified colors have enough contrast between them".
I don't know if this has been discussed previously, but what should happen if only one color was provided to
scrollbar-color
?My proposal is that when one color is provided to
scrollbar-color
, it would be used by the UA to automatically define the color scheme for the scrollbar (to "tint" it, so to speak).This would allow authors to easily style the scrollbars on their pages while the UA ensures adequate accessibility by making sure that the specific colors have enough contrast between them.