You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<pre class="lang-css">color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)</pre>
506
+
507
+
The calculation is as follows:
508
+
* <span class="swatch" style="--color: wheat"></span> wheat (#f5deb3), the background, has relative luminance 0.749
509
+
* <span class="swatch" style="--color: bisque"></span> bisque (#ffe4c4) has relative luminance 0.807 and contrast ratio <strong>1.073</strong>
510
+
* <span class="swatch" style="--color: darkgoldenrod"></span> darkgoldenrod (#b8860b) has relative luminance 0.273 and contrast ratio <strong>2.477</strong>
511
+
* <span class="swatch" style="--color: olive"></span> olive (#808000 ) has relative luminance 0.200 and contrast ratio <strong>3.193</strong>
512
+
* <span class="swatch" style="--color: sienna"></span> sienna (#a0522d) has relative luminance 0.137 and contrast ratio <strong>4.274</strong>
513
+
* <span class="swatch" style="--color: darkgreen"></span> darkgreen (#006400 ) has relative luminance 0.091 and contrast ratio <strong>5.662</strong>
514
+
* <span class="swatch" style="--color: maroon"></span> maroon (#800000 ) has relative luminance 0.046 and contrast ratio <strong>8.333</strong>
515
+
516
+
517
+
The first color in the list which meets the desired contrast ratio of 4.5 is <span class="swatch" style="--color: darkgreen"></span> darkgreen.
518
+
519
+
</div>
520
+
521
+
<div class="example">
522
+
<pre class="lang-css">color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)</pre>
523
+
524
+
The calculation is as follows:
525
+
* the relative luminances and contrast ratios are the same as the previous example.
526
+
527
+
The first color in the list which meets the desired contrast ratio of 5.8 is <span class="swatch" style="--color: maroon"></span> maroon.
528
+
529
+
</div>
530
+
491
531
The colors in the list (after the keyword vs) are tested sequentially,
492
532
from left to right;
493
533
a color is the temporary winner
494
-
if it has the highest contrast of all those tested so far,
495
-
and once the end of the list is reached, the current temporary winner is the overall winner.
534
+
if it has the highest contrast of all those tested so far.
535
+
536
+
List traversal is terminated once the target contrast has been meet or exceeded.
537
+
538
+
Once the end of the list is reached, if there is no target contrast,
539
+
the current temporary winner is the overall winner.
496
540
Thus, if two colors in the list happen to have the same contrast,
497
541
the earlier in the list wins
498
542
because the later one has the same contrast, not higher.
499
543
544
+
If there is a target contrast,
545
+
and the end of the list is reached without meeting that target,
546
+
either 'white' or 'black' is returned,
547
+
whichever has the higher contrast.
548
+
549
+
<div class="example">
550
+
<pre class="lang-css">color-contrast(wheat vs bisque, darkgoldenrod, olive to AA)</pre>
551
+
552
+
The calculation is as follows:
553
+
* the relative luminances and contrast ratios are the same as the previous example.
554
+
555
+
No color in the list meets the desired contrast ratio of 4.5,
556
+
so <span class="swatch" style="--color: black"></span> black
0 commit comments