How to calculate
Linearize the sRGB channels and calculate their weighted relative luminances. Add 0.05 to both luminances, then divide the lighter value by the darker. Compare the unrounded ratio with the chosen threshold.
Worked example
Use Foreground hex color #000000 · Background hex color #ffffff. The result is 21:1.
Input and result notes
Enter 3- or 6-digit hex colors. For overlaid text, enter the resulting foreground and background colors as they appear after compositing.
W3C WCAG 2.2 contrast thresholds and luminance