Understanding Contrast
Contrast Ratio ### |
WCAG Grade
|
1. Convert the HEX color to RGB.
RGB 1 | RGB 2 |
2. Divide each color by 255 to get a linear value between 0 and 1.
r: g: b: |
r: g: b: |
3. Apply Gamma Correction
If value < than .03928, divide by 12.92.
Otherwise, add .055 and divide total by 1.055 and take result to the power of 2.4
r: g: b: |
r: g: b: |
4. Calculate luminance
(r X .2126) + (g X .7152) + (b X 0.0722)
Luminance 1 | Luminance 2 |
5. Determine contrast between colors.
(L1 + 0.05) / (L2 + 0.05)
Contrast Result
Credits:
- NES.css
- Lee Verou's Contrast Ratio Site(helped me understand the math)
- The Princess Icon by Freepik from www.flaticon.com is licensed by CC 3.0 BY
Reference
- Understanding Gamma Correction
- Learn more about Gamma Correction
- Relative luminance
- Stacie's list of Accessibility Resources>
- 1. Wavelength of Maximum Human Visual Sensitivity Susan Zhao 2007
Parts of the article were initially posted as 'The Bright Stuff' at: staciearellano.com/the-bright-stuff/in 2019.