Contrast Ratio Calculator

Last updated: 2026-09-01

Contrast Ratio Calculator — Free online contrast ratio calculator. Enter light luminance and dark luminance to get instant results.
Inputs
Result
Enter values and press Calculate
Common Examples — Click to Fill
Light luminanceDark luminance
Small print 1280
Standard 1910
Large poster 2550
Banner 3820
Billboard 5100

TL;DR: To calculate the contrast ratio, divide the luminance of the lighter color (L1) by the luminance of the darker color (L2), using the formula (L1 + 0.05) / (L2 + 0.05), and then compare the resulting number (from 1:1 to 21:1) against WCAG standards for accessibility.

What Is the Contrast Ratio Calculator?

This free online tool calculates the contrast ratio between two luminance values, typically representing the foreground (like text) and background colors on a screen. The contrast ratio is a numerical measurement that expresses the difference in perceived brightness between two colors. It is a fundamental metric in web design, user interface (UI) development, and digital accessibility because it directly determines whether text is legible for users with low vision, color blindness, or those viewing screens in bright environments.

The tool is essential for web developers, UI/UX designers, digital marketers, and content creators who must comply with the Web Content Accessibility Guidelines (WCAG). These guidelines define specific contrast ratio thresholds for normal text, large text, and graphical elements. Without a calculator, manually deriving a ratio from RGB or hex color values is complex and error-prone because human perception of luminance is non-linear. By focusing directly on light luminance and dark luminance inputs, this calculator simplifies the process into a single, accurate division.

The calculation itself is based on the W3C’s published algorithm for relative luminance and contrast ratio. It applies a specific formula to the luminance values (which should be between 0 and 1, where 0 is black and 1 is white). The final result is a ratio such as 4.5:1 or 21:1. This number is not just a theoretical figure; it is a legal and functional benchmark. Meeting a 4.5:1 ratio for standard text is a hard requirement for many government and enterprise websites, making this calculator a crucial part of the development workflow.

How to Use the Calculator

Using this calculator is a straightforward process designed to deliver instant feedback. The tool requires two specific numeric inputs representing the relative luminance of your chosen colors. Here is the step-by-step process, assuming you already have the luminance values from tools like a color picker or a design application.

  1. Locate the Input Fields: Find the two input boxes. They are typically labeled 'Light Luminance' (or L1) and 'Dark Luminance' (or L2).
  2. Enter the Light Value: In the first field, enter the luminance of the lighter color. This value must be a decimal number between 0 and 1. For example, pure white is '1', while a very light gray might be '0.8'.
  3. Enter the Dark Value: In the second field, enter the luminance of the darker color. This value must also be between 0 and 1, but should be numerically smaller than the first field. Pure black is '0', while a dark gray might be '0.2'.
  4. Click Calculate: Press the 'Calculate' or 'Submit' button. The tool will automatically process the inputs.
  5. View the Results: The calculator will instantly display the final contrast ratio (e.g., 12.63:1) and likely the relative luminance of each color. It may also indicate whether this ratio passes WCAG AA or AAA standards.

Formula and Calculation Method

The calculation method behind this tool is defined by the World Wide Web Consortium (W3C) in their Web Content Accessibility Guidelines (WCAG) 2.1. The formula is deceptively simple, but it hinges on the accuracy of the luminance inputs. The tool first verifies the input range (must be 0 to 1) and then applies the following mathematical equation.

The formula for Contrast Ratio (CR) is:

Contrast Ratio = (L1 + 0.05) / (L2 + 0.05)

In this formula, L1 represents the relative luminance of the lighter color, and L2 represents the relative luminance of the darker color. The value 0.05 is a constant added to both values to adjust for the fact that the absolute black has some ambient light reflectance in real-world viewing conditions. This constant prevents the ratio from dividing by zero when the dark color is pure black (L2 = 0).

Let’s walk through a concrete worked example to demonstrate the process. Suppose you are testing a dark gray text on a white background. You have already determined that the white background has a relative luminance of 0.95 (L1) and the dark gray text has a relative luminance of 0.35 (L2).

Step 1: Add the constant 0.05 to L1. (0.95 + 0.05 = 1.00).
Step 2: Add the constant 0.05 to L2. (0.35 + 0.05 = 0.40).
Step 3: Divide the results. (1.00 / 0.40 = 2.50).
Result: The contrast ratio is 2.5:1. This is a low ratio and would likely fail the WCAG AA requirement of 4.5:1 for standard text, meaning the text would be hard to read for many users.

The tool performs this calculation in reverse order if you enter the values correctly: it identifies the larger number as L1 and the smaller as L2 before applying the formula. This ensures the final ratio is always between 1:1 (identical colors) and 21:1 (black vs. white).

Practical Examples

To understand how the contrast ratio functions in real-world design, let’s look at three scenarios using different luminance inputs. These examples illustrate how the same formula yields very different results based on the brightness of the colors involved.

Scenario Light Luminance (L1) Dark Luminance (L2) Calculated Ratio WCAG Result
Body Text on Dark Background 0.95 (Near White) 0.15 (Dark Charcoal) (1.00)/(0.20) = 5:1 Passes AA (4.5:1) for normal text.
Icons on Light Gray Background 0.85 (White-ish) 0.30 (Mid-Gray) (0.90)/(0.35) = 2.57:1 Fails AA for normal text; passes only for large graphics.
Normal Link Text on White 1.00 (Pure White) 0.20 (Standard Blue) (1.05)/(0.25) = 4.2:1 Fails AA (4.5:1) for standard text, needs darker blue.

In the first example, a ratio of 5:1 is sufficient for most standard text. In the second example, the ratio of 2.57:1 is too low for any text smaller than 18pt (bold) or 24pt regular. The tool helps you see these differences instantly, allowing you to adjust your luminance values on the fly to hit the required threshold for your specific use case.

Tips for Accurate Results

Getting the correct contrast ratio is critical, but it is easy to make mistakes if you do not pay attention to the input data. The following tips will help you avoid the most common errors when using this specific calculator.

  • Verify the Units and Scale: The most common mistake is entering RGB values (0-255) instead of relative luminance values (0.0 to 1.0). This calculator expects luminance, not color codes. If your design tool shows luminance as a percentage (e.g., 50%), you must convert it to a decimal (0.5) before entering it.
  • Check the Range of Validity: Luminance values are physically bounded between 0 (black) and 1 (white). If you enter a value greater than 1, the calculator will produce a mathematically incorrect ratio. Always ensure your inputs are within the valid range [0, 1].
  • Avoid Rounding Intermediate Results: When manually calculating, do not round L1 or L2 to one decimal place before applying the formula. Rounding 0.179 to 0.2 can change the final ratio significantly (e.g., from 4.5:1 to 4.0:1). Enter the full precision luminance value into the calculator for the most accurate output.
  • Ensure Correct Ordering: Always place the lighter luminance (higher number) in the 'Light' field. While the formula divides L1 by L2, if you swap them, you will get a fraction (e.g., 0.5 instead of 2:1), which is an invalid contrast ratio. The tool assumes you will input them correctly, but it is good practice to double-check your values.

Frequently Asked Questions

What is the difference between contrast ratio and luminance?

Luminance is an absolute measure of the light emitted from a screen, ranging from 0 (black) to 1 (white). It represents how bright a specific color actually is. Contrast ratio is a relative measure; it describes the difference in luminance between two colors. You calculate contrast by dividing the brighter luminance by the darker luminance (with the +0.05 correction). In short, luminance is the input (the raw data), and contrast ratio is the output (the relationship between two luminance values). A color can have a fixed luminance, but its contrast ratio only exists relative to another color.

Why does the formula add 0.05 to both numbers?

The constant 0.05 is a perceptual adjustment defined by the W3C. It accounts for the fact that in normal viewing conditions, true black (luminance 0) is almost impossible to achieve due to ambient light reflecting off the screen. Even if a display is off, some light is reflected. Adding 0.05 to both the light and dark values ensures that the contrast ratio can never be infinite (which would happen if you divided by zero when the dark color is black). It also standardizes the maximum ratio at 21:1 (pure white vs. pure black), which represents the absolute dynamic range of a typical display.

Is a 3:1 contrast ratio sufficient for all text?

No. According to WCAG 2.1, a 3:1 contrast ratio is only sufficient for large text (18pt or 14pt bold and above) and for graphical elements (like icons and charts). For standard body text, the minimum requirement is 4.5:1 to meet WCAG AA compliance. If you are targeting WCAG AAA, the bar is even higher, requiring 7:1 for standard text and 4.5:1 for large text. This calculator helps you determine if your specific text size and weight meet the required threshold, ensuring your content is accessible to the widest possible audience.

FAQ

What is the Contrast Ratio Calculator used for?

The Contrast Ratio Calculator is designed to compute the contrast ratio between two colors, typically a foreground and background color, based on the WCAG (Web Content Accessibility Guidelines) standards. It helps designers and developers ensure that text and UI elements meet accessibility requirements for readability, especially for users with low vision or color blindness.

How do I input colors into the calculator?

You can input colors using HEX codes (e.g., #FFFFFF), RGB values, or HSL values, depending on which format you prefer. The calculator will automatically convert your input to a normalized luminance value, which is then used to calculate the ratio. Simply enter the two colors in their respective fields and click the 'Calculate' button to get an instant result.

What does the contrast ratio number mean, and what is a 'passing' score?

The contrast ratio is expressed as a numeric value, typically ranging from 1:1 (no contrast) to 21:1 (maximum contrast for black on white). According to WCAG 2.1, a ratio of at least 4.5:1 is required for normal text, while large text (18pt or 14pt bold) needs a minimum of 3:1, and for AAA compliance, the thresholds rise to 7:1 and 4.5:1 respectively. The calculator will also indicate whether your result meets these guidelines.

Can I use the calculator for non-text elements like icons or graphical objects?

Yes, the Contrast Ratio Calculator can be used for any graphical elements, not just text, as long as you have the two colors in question. For non-text UI components (like icons, buttons, or borders), WCAG recommends a contrast ratio of at least 3:1 against adjacent colors. The calculator provides the same ratio output, so you can manually compare it to the required threshold for your specific use case.