@@ -63,17 +63,28 @@ Computing a Contrasting Color: the ''contrast-color()'' function {#colorcontrast
63
63
Its syntax is:
64
64
65
65
66
- <> = contrast-color( <> [[ vs <> # ]? to <> ]? )
66
+ <> = contrast-color(
67
+ [ [ <> && [ tbd-fg | tbd-bg ] && <> ? ] |
68
+ [ <> && [ tbd-fg | tbd-bg ] && <> , <> # ] )
67
69
<> = <>
68
70
69
71
70
72
The only mandatory argument is the base color
71
73
against which the contrast is computed.
72
74
This is typically (but not necessarily) a background color.
73
75
74
- An optional list of contrast color candidates may be provided after a ''vs'' keyword.
76
+ The optional list of <> values represents
77
+ the color candidates .
75
78
If no candidates are provided, the default candidates are used: ''white, black'' .
76
79
80
+ The ''tbd-fg'' and ''tbd-bg'' keywords
81
+ indicate the role of the [=base color=] in calculating the contrast:
82
+ as text against a list of [=color candidate|candidate=] background colors (text )
83
+ or as a background against a list of [=color candidate|candidate=] text colors.
84
+ (The effective contrast of a pair of colors depends on their usage.)
85
+
86
+ ISSUE (#7359): The keywords to specify whether the
[=base color=] is a foreground or background are
TBD
.
87
+
77
88
The <> argument specifies the contrast algorithm to use.
78
89
If no [=color candidates=] have been provided,
79
90
<> may be omitted,
@@ -113,7 +124,7 @@ If there is a target contrast
113
124
https://colorjs.io/notebook/?storage=https%3A%2F%2Fgist.github.com%2Fsvgeesus%2Fec249f376fcecbaa8794f75dbfc1dacf
114
125
-->
115
126
116
- contrast-color(wheat
vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon
to wcag2(aa) )
127
+ contrast-color(wheat
tbd-bg wcag2(aa), bisque, darkgoldenrod, olive, sienna, darkgreen, maroon)
117
128
118
129
The calculation is as follows:
119
130
* wheat (#f5deb3), the background, has relative luminance 0.749
@@ -128,7 +139,7 @@ If there is a target contrast
128
139
129
140
130
141
131
- contrast-color(wheat
vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon
to wcag2(5.8) )
142
+ contrast-color(wheat
tbd-bg wcag2(5.8), bisque, darkgoldenrod, olive, sienna, darkgreen, maroon)
132
143
133
144
The calculation is as follows:
134
145
* the relative luminances and contrast ratios are the same as the previous example.
@@ -137,7 +148,7 @@ If there is a target contrast
137
148
138
149
139
150
140
- contrast-color(wheat
vs bisque, darkgoldenrod, olive
to wcag2(AA) )
151
+ contrast-color(wheat
tbd-bg wcag2(AA), bisque, darkgoldenrod, olive)
141
152
142
153
The calculation is as follows:
143
154
* the relative luminances and contrast ratios are the same as the previous example.
@@ -164,7 +175,7 @@ If no target contrast is specified
164
175
165
176
166
177
--myAccent: #b22222;
167
- color: contrast-color(wheat vs tan, sienna, var(--myAccent), #d2691e to wcag2 )
178
+ color: contrast-color(wheat tbd-bg wcag2, tan, sienna, var(--myAccent), #d2691e)
168
179
169
180
170
181
The calculation is as follows:
@@ -182,7 +193,7 @@ If no target contrast is specified
182
193
foo {
183
194
--bg: hsl(200 50% 80%);
184
195
--purple-in-hsl: hsl(300 100% 25%);
185
- color: contrast-color(var(--bg) vs hsl(200 83% 23%), purple, var(--purple-in-hsl) to wcag2 );
196
+ color: contrast-color(var(--bg) tbd-fg wcag2, hsl(200 83% 23%), purple, var(--purple-in-hsl));
186
197
}
187
198
188
199
@@ -290,7 +301,7 @@ If no target contrast is specified
290
301
For example, given the value
291
302
292
303
293
- contrast-color(rgb(179 213 230) vs cadetblue, hsl(200 83% 23%) to wcag2(AA ))
304
+ contrast-color(rgb(179 213 230) tbd-bg wcag2(AA), cadetblue, hsl(200 83% 23%))
294
305
295
306
296
307
the contrast with cadetblue is 1.97
@@ -311,13 +322,13 @@ If no target contrast is specified
311
322
the value
312
323
313
324
314
- contrast-color(currentColor vs hsl(200 83% 23%), purple to wcag2(AA) )
325
+ contrast-color(currentColor tbd-bg wcag2(AA), hsl(200 83% 23%), purple)
315
326
316
327
317
328
has the computed value
318
329
319
330
320
- contrast-color(currentColor vs rgb(10 75 107), rgb(128 0 128) to wcag2(4.5 ))
331
+ contrast-color(currentColor tbd-bg wcag2(4.5), rgb(10 75 107), rgb(128 0 128))
321
332
322
333
323
334
@@ -401,14 +412,14 @@ is the same as that specified in
401
412
402
413
403
414
The winner of this contrast choice
404
- contrast-color(wheat
vs olive, sienna, maroon)
415
+ contrast-color(wheat
tbd-bg wcag2, olive, sienna, maroon)
405
416
is maroon,
406
417
so the result is serialized as
407
418
408
419
"rgb(128 0 0)".
409
420
410
421
While the winner of
411
- contrast-color(wheat
vs color(prophoto-rgb 0.4 0.4 0.2), color(display-p3 0.45 0.08 0.05))
422
+ contrast-color(wheat
tbd-bg wcag2, color(prophoto-rgb 0.4 0.4 0.2), color(display-p3 0.45 0.08 0.05))
412
423
is color(display-p3 0.45 0.08 0.05),
413
424
so the result is serialized as
414
425
0 commit comments