contrastRatio(against:) converts both colors to opaque sRGB and returns the WCAG 2 ratio (L1 + 0.05) / (L2 + 0.05). Black on white is 21.
contrastRatio(against:)
(L1 + 0.05) / (L2 + 0.05)
21
The letters are the foreground. The caption is the ratio, drawn in ink so it stays readable when the sample itself fails contrast.
let gray = Color<SRGB>( red: 118.0 / 255.0, green: 118.0 / 255.0, blue: 118.0 / 255.0 ) let white = Color<SRGB>(red: 1, green: 1, blue: 1) let ratio = gray.contrastRatio(against: white)
#767676 on white is 4.54:1. WCAG defines the ratio for in-gamut sRGB. Out-of-gamut channels are not clamped and can produce a ratio outside 1...21.
#767676
4.54:1
1...21
See also Conversions, Interpolation, Difference.
There was an error while loading. Please reload this page.
Colorful
Home Conversions Interpolation Contrast Difference