Contrast ratio
A contrast ratio is the numerical ratio of the higher relative luminance to the lower relative luminance of two colors.
Architecting Accessibility
A contrast ratio is a luminance-based numerical comparison between foreground and background colors, ranging from 1:1 to 21:1.
- How it is used
- Measures whether text, UI components, and graphics stand out sufficiently from their backgrounds.
- How deep it goes
- Defines the luminance-based range, gives content-specific thresholds, and distinguishes WCAG conformance from supplementary APCA guidance.
- Examples
- Illustrates faint form borders, focus indicators, chart lines, and a color pairing that WCAG and APCA assess differently.
- What you can do after
- Diagnose/debug with it by checking text, component boundaries, and meaningful graphics against their backgrounds.
Read how Architecting Accessibility explains contrast ratio →
D3.js in Action, Third Edition
A contrast ratio is a numerical measure of the relative luminance difference between foreground and background colors.
- How it is used
- Guides accessible color selection and verification for text, controls, geometric shapes, and visualization legends.
- How deep it goes
- Defines numerical thresholds, names verification tools, and demonstrates palette revision without deriving the underlying luminance calculation.
- Examples
- Uses scatterplot circles, legends, buttons, a white background, and revised categorical colors to demonstrate passing and failing ratios.
- What you can do after
- Operate the WCAG Color contrast checker and WebAIM checker to evaluate colors and revise inaccessible visualization elements.
Read how D3.js in Action, Third Edition explains contrast ratio →
Math for Web Design
A contrast ratio is a numerical comparison of the relative luminances of two colors, calculated with the higher luminance as the numerator.
- How it is used
- Checks whether text and background colors meet WCAG readability thresholds instead of relying on visual judgment.
- How deep it goes
- Works from relative luminance through the ratio formula, numerical examples, and JavaScript calculation and compliance checks.
- Examples
- Compares blue against white and red, gray against white, and a JavaScript-based contrast calculator.
- What you can do after
- Build it from scratch with JavaScript to calculate ratios from RGB hex codes and check AA or AAA compliance.
Everyday Data Visualization
A contrast ratio is a numeric comparison of the relative luminance of a lighter color with that of a darker color.
- How it is used
- Guides accessible color choices for text and data visualizations.
- How deep it goes
- Defines the formula and thresholds, but defers detailed luminance arithmetic to calculators.
- Examples
- Compares blue bars with light gray backgrounds and dark-gray borders.
- What you can do after
- Apply an accessible-colors calculator to check text, borders, and visualization elements.
Read how Everyday Data Visualization explains contrast ratio →
Also covered in
- CSS in Depth, Second Edition
- Vanilla WebIn early access (MEAP)
What to know first
- opacityOpacity is the visual property specifying how opaque or transparent a rendered element or color appears.
- WCAGThe Web Content Accessibility Guidelines are W3C recommendations with testable criteria for making web content accessible to people with disabilities.
Related concepts
- WCAGused by · The Web Content Accessibility Guidelines are W3C recommendations with testable criteria for making web content accessible to people with disabilities.
- brightnessmeasures · Brightness is the perceived or measured intensity or lightness of a color, image, visual stimulus, or light source.
- relative luminanceuses · Relative luminance is a normalized measure of a color’s apparent brightness calculated from the weighted contributions of its linearized red, green, and blue components.
- ratiokind of · A ratio is a quantitative comparison of two quantities expressed through their relative sizes or quotient.
- APCAalternative to · APCA, the Accessible Perceptual Contrast Algorithm, is a perception-based color-contrast algorithm that estimates visual contrast using lightness, polarity, font size, and font weight.
Questions about contrast ratio
What is contrast ratio?
A contrast ratio is the numerical ratio of the higher relative luminance to the lower relative luminance of two colors.
Which Manning books explain contrast ratio?
Architecting Accessibility, D3.js in Action, Third Edition, Math for Web Design and Everyday Data Visualization.
What should I know before learning contrast ratio?
Manning books that teach contrast ratio usually introduce opacity and WCAG first.
What is the difference between contrast ratio and APCA?
A contrast ratio is the numerical ratio of the higher relative luminance to the lower relative luminance of two colors. APCA, the Accessible Perceptual Contrast Algorithm, is a perception-based color-contrast algorithm that estimates visual contrast using lightness, polarity, font size, and font weight.
What is contrast ratio a kind of?
Contrast ratio is a kind of ratio. A ratio is a quantitative comparison of two quantities expressed through their relative sizes or quotient.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



