Contrast Ratio
A ratio that expresses the difference in lightness between the foreground color and the background color as a number. WCAG requires 4.5:1 or higher as the readability criterion for text.
Contrast ratio is a ratio that expresses, as a number, the relative difference in lightness between the foreground color (text or icons) and the background color. It is expressed in a range from 1:1 (no difference) to 21:1 (black and white), and it is an important metric for guaranteeing the readability of text in web accessibility.
The W3C's WCAG (Web Content Accessibility Guidelines) requires, at Level AA, 4.5:1 or higher for normal text and 3:1 or higher for large text (Success Criterion 1.4.3). Level AAA is even stricter, at 7:1 or higher for normal text and 4.5:1 or higher for large text (Success Criterion 1.4.6). "Large text" here means 18pt or larger, or 14pt or larger if bold. Converted to CSS px, 1pt is 1/72 inch and 1px is 1/96 inch, so 18pt is 24px and 14pt is about 18.7px. Body text at 16px does not count as "large text," so almost all body text is judged against the 4.5:1 criterion. These four values have not changed from WCAG 2.0 through 2.2.
There are also criteria for things other than text. Success Criterion 1.4.11 requires a ratio of 3:1 or higher against adjacent colors for the boundaries and state indicators of UI components needed for operation, and for graphics needed to understand the content. Form borders, focus rings, icons, and the series colors of charts are covered, and adjusting only the color of body text while overlooking UI components is a common gap.
Japan's JIS X 8341-3:2016 is a standard whose content matches WCAG 2.0, and the values of its contrast success criteria are also the same. The operational guidelines for public institutions require conformance at Level AA, but JIS itself is a voluntary standard, and no law directly obliges conformance to JIS. The practical criterion for judgment is not to assert flatly that "JIS makes it mandatory," but to check what you have committed to in your procurement specifications or your company's accessibility policy.
The calculation of the contrast ratio uses the relative luminance of the colors. The formula is (L1 + 0.05) / (L2 + 0.05), where L1 is the relative luminance of the lighter color and L2 that of the darker color. Relative luminance is calculated from the RGB values while taking sRGB gamma correction into account, so it differs from a simple difference in RGB values. As a result, a "middle gray" to the eye leans considerably toward the dark side in numerical terms. Measured against a white background (#ffffff), #333333 is 12.63:1, #595959 is 7.00:1, #767676 is 4.54:1, and #999999 is 2.85:1. In other words, #767676 is almost exactly on the AA boundary, and #999999 cannot be used for body text. You can check individual colors with tools such as Chrome DevTools, axe, and Lighthouse.
When supporting dark mode, you need to check the contrast ratio in both light mode and dark mode. Even the same gray can shift the ratio a great deal when the background changes. #aaaaaa meets AAA at 9.04:1 on a black background (#000000), but on a white background it is 2.32:1 and does not even reach AA. Conversely, a dark gray that was safe in light mode sinks into the background in dark mode (the combination of #333333 and #1a1a1a is 1.38:1). Managing the colors for each mode separately with CSS custom properties and verifying each one is the reliable approach. If you use a semi-transparent text color (rgba or opacity), the result will not match reality unless you calculate with the effective color after it is composited with the background, not with the specified value. For text placed over images or gradients, judge it at the part with the worst conditions.
A common misconception is that the higher the contrast ratio, the better. Some users report that text looks blurred (halation) with pure black and pure white (21:1), and designs that use a gray with slightly reduced lightness for body text are not unusual. However, this is a design choice, not a requirement of the standard, and lowering it too far will fall below the criterion. Rather than adjusting toward the upper limit, it is safer to think in the order of choosing the reading feel within a range that reliably exceeds AA.
In relation to character counting, text with a low contrast ratio is hard to read and causes users to fail to recognize characters accurately. Especially with small font sizes and thin font weights, securing a sufficient contrast ratio becomes even more important. In the UI design of character counting tools as well, paying attention to the contrast ratio between the input text and the background improves users' work efficiency.