@@ -63,17 +63,28 @@ Computing a Contrasting Color: the ''contrast-color()'' function {#colorcontrast
63
63
Its syntax is:
64
64
65
65
<pre class='prod'>
66
- <<contrast-color()>> = contrast-color( <<color>> [[ vs <<color>> # ]? to <<target-contrast>> ]? )
66
+ <<contrast-color()>> = contrast-color(
67
+ [ [ <<color>> && [ tbd-fg | tbd-bg ] && <<target-contrast>> ? ] |
68
+ [ <<color>> && [ tbd-fg | tbd-bg ] && <<target-contrast>> , <<color>> # ] )
67
69
<<target-contrast>> = <<wcag2>>
68
70
</pre>
69
71
70
72
The only mandatory argument is the <dfn lt="contrast base color" local-lt="base color">base color</dfn>
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 <dfn local-lt="color candidates">contrast color candidates</dfn> may be provided after a ''vs'' keyword.
76
+ The optional list of <<color>> values represents
77
+ the <dfn lt="contrast color candidates" local-lt="color candidates">color candidates</dfn> .
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 (<dfn for="contrast-color()" value>text</dfn> )
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 <abbr title="to be decided"> TBD</abbr> .
87
+
77
88
The <dfn><<target-contrast>></dfn> argument specifies the contrast algorithm to use.
78
89
If no [=color candidates=] have been provided,
79
90
<<target-contrast>> may be omitted,
@@ -113,7 +124,7 @@ If there is a target contrast</h4>
113
124
https://colorjs.io/notebook/?storage=https%3A%2F%2Fgist.github.com%2Fsvgeesus%2Fec249f376fcecbaa8794f75dbfc1dacf
114
125
-->
115
126
<div class="example">
116
- <pre class="lang-css"> contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to wcag2(aa) )</pre>
127
+ <pre class="lang-css"> contrast-color(wheat tbd-bg wcag2(aa), bisque, darkgoldenrod, olive, sienna, darkgreen, maroon)</pre>
117
128
118
129
The calculation is as follows:
119
130
* <span class="swatch" style="--color: wheat"></span> wheat (#f5deb3), the background, has relative luminance 0.749
@@ -128,7 +139,7 @@ If there is a target contrast</h4>
128
139
</div>
129
140
130
141
<div class="example">
131
- <pre class="lang-css"> contrast-color(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to wcag2(5.8) )</pre>
142
+ <pre class="lang-css"> contrast-color(wheat tbd-bg wcag2(5.8), bisque, darkgoldenrod, olive, sienna, darkgreen, maroon)</pre>
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</h4>
137
148
</div>
138
149
139
150
<div class="example">
140
- <pre class="lang-css"> contrast-color(wheat vs bisque, darkgoldenrod, olive to wcag2(AA) )</pre>
151
+ <pre class="lang-css"> contrast-color(wheat tbd-bg wcag2(AA), bisque, darkgoldenrod, olive)</pre>
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</h4>
164
175
<div class="example">
165
176
<pre class="lang-css">
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
</pre>
169
180
170
181
The calculation is as follows:
@@ -182,7 +193,7 @@ If no target contrast is specified</h4>
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
</pre>
188
199
@@ -290,7 +301,7 @@ If no target contrast is specified</h4>
290
301
For example, given the value
291
302
292
303
<pre class="lang-css">
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
</pre>
295
306
296
307
the contrast with cadetblue is <strong> 1.97</strong>
@@ -311,13 +322,13 @@ If no target contrast is specified</h4>
311
322
the value
312
323
313
324
<pre class="lang-css">
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
</pre>
316
327
317
328
has the computed value
318
329
319
330
<pre class="lang-css">
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
</pre>
322
333
323
334
</div>
@@ -401,14 +412,14 @@ is the same as that specified in
401
412
402
413
<div class="example">
403
414
The winner of this contrast choice
404
- <pre> contrast-color(wheat vs olive, sienna, maroon)</pre>
415
+ <pre> contrast-color(wheat tbd-bg wcag2, olive, sienna, maroon)</pre>
405
416
is maroon,
406
417
so the result is serialized as
407
418
<span class="swatch" style="--color: maroon"></span>
408
419
"rgb(128 0 0)".
409
420
410
421
While the winner of
411
- <pre> contrast-color(wheat vs color(prophoto-rgb 0.4 0.4 0.2), color(display-p3 0.45 0.08 0.05))</pre>
422
+ <pre> contrast-color(wheat tbd-bg wcag2, color(prophoto-rgb 0.4 0.4 0.2), color(display-p3 0.45 0.08 0.05))</pre>
412
423
is color(display-p3 0.45 0.08 0.05),
413
424
so the result is serialized as
414
425
<span class="swatch" style="--color: rgb(49.277% 0.414% 0.524%)"></span>
0 commit comments