Color Contrast Generator

Free Web Accessibility Tool

Color Contrast Checker

Check the contrast ratio between text and background colors. Test your color combination against WCAG AA and AAA requirements for normal text, large text and user interface components.

Contrast Preview

Color contrast describes the difference in relative luminance between text or another interface element and the background behind it. Sufficient contrast makes content easier to read and helps users distinguish text, buttons, links and controls in different lighting conditions and on different screens.

WCAG accessibility guidelines define minimum contrast ratios for readable text. Normal text should have a contrast ratio of at least 4.5:1 for Level AA, while large text should have a ratio of at least 3:1. Higher ratios may be required when targeting the stricter Level AAA requirements.

Use the controls above to select a text color and a background color. The tool calculates their contrast ratio and shows whether the combination passes the relevant WCAG thresholds. If the result fails, try making the text darker, making the background lighter, or increasing the difference between the two colors.



Understanding the Contrast Result

The result shows the contrast ratio between the selected foreground and background colors. A higher ratio generally means that the two colors are easier to distinguish.

Test the same colors in all relevant states, including normal, hover, focus, active and disabled states. A combination that passes in one state may fail after the background or text color changes.

How to Use the Color Contrast Checker

  1. Enter or select the text color.
  2. Enter or select the background color.
  3. Review the calculated contrast ratio.
  4. Check whether the colors pass WCAG AA for normal text.
  5. Check whether they pass WCAG AA for large text.
  6. Review the stricter WCAG AAA results if required.
  7. Adjust one of the colors if the combination fails.
  8. Test the final colors in the actual interface where they will be used.

What Is This Color Contrast Checker?

This Color Contrast Checker is a free accessibility tool that calculates the contrast ratio between a foreground color and a background color. It helps designers and developers determine whether text is likely to meet WCAG contrast requirements.

The tool can be used when choosing colors for headings, paragraphs, buttons, links, form fields, navigation, badges, alerts and other user interface components.

WCAG Color Contrast Requirements

WCAG defines different contrast thresholds depending on the size and purpose of the content.

Content type WCAG AA WCAG AAA
Normal text 4.5:1 7:1
Large text 3:1 4.5:1
UI components and meaningful graphics 3:1 Not defined by the same AAA text criterion

Large text generally means text that is at least 18pt regular or 14pt bold. In common CSS pixel terms, these values are approximately 24px regular or 18.66px bold.

Logos, inactive controls, invisible content and purely decorative text may be exempt from the normal text contrast requirement. However, essential information should never rely on a low-contrast presentation.

Color Contrast Examples

Dark Text on a Light Background

Dark navy or charcoal text on a pale background often provides strong contrast while appearing softer than pure black.

Light Text on a Dark Background

White or off-white text can work well on dark blue, charcoal and black backgrounds when the calculated contrast remains sufficient.

Accessible Button Colors

A button label must contrast with the button background, while the button boundary or visual shape may also need enough contrast against the surrounding page.

Link Color Contrast

Links should remain readable against their background and should not rely on color alone when they appear inside surrounding body text.

Focus Indicator Contrast

Custom keyboard focus outlines must remain distinguishable from the colors immediately beside them.

Color Contrast and WCAG Guide

What Is Color Contrast?

Color contrast describes the measurable difference in relative luminance between two colors. For text, the comparison is usually made between the text color and the background directly behind it.

The contrast ratio ranges from 1:1 for identical colors to 21:1 for black and white.

Contrast Ratio Formula

After calculating the relative luminance of both colors, the contrast ratio is calculated with the lighter luminance as L1 and the darker luminance as L2.

contrast ratio = (L1 + 0.05) / (L2 + 0.05)

Relative Luminance Formula

Relative luminance is calculated from linearized red, green and blue channel values.

L = 0.2126 × R + 0.7152 × G + 0.0722 × B

Converting sRGB Channels to Linear RGB

Each 8-bit channel must first be divided by 255. The normalized channel is then converted to a linear value.

if channel <= 0.04045:


linear = channel / 12.92

otherwise:
linear = ((channel + 0.055) / 1.055) ^ 2.4

JavaScript Contrast Ratio Function

function normalizeHex(hex) {


let value = hex.trim().replace("#", "");

if (/^[0-9a-f]{3}$/i.test(value)) {
value = value
.split("")
.map(character => character + character)
.join("");
}

if (!/^[0-9a-f]{6}$/i.test(value)) {
throw new Error("Enter a valid 3-digit or 6-digit HEX color.");
}

return value;
}

function hexToRgb(hex) {
const value = normalizeHex(hex);

return {
r: parseInt(value.slice(0, 2), 16),
g: parseInt(value.slice(2, 4), 16),
b: parseInt(value.slice(4, 6), 16)
};
}

function srgbChannelToLinear(channel) {
const normalized = channel / 255;

if (normalized <= 0.04045) {
return normalized / 12.92;
}

return Math.pow((normalized + 0.055) / 1.055, 2.4);
}

function relativeLuminance(hex) {
const { r, g, b } = hexToRgb(hex);

const red = srgbChannelToLinear(r);
const green = srgbChannelToLinear(g);
const blue = srgbChannelToLinear(b);

return (
0.2126 * red +
0.7152 * green +
0.0722 * blue
);
}

function contrastRatio(foreground, background) {
const foregroundLuminance = relativeLuminance(foreground);
const backgroundLuminance = relativeLuminance(background);

const lighter = Math.max(
foregroundLuminance,
backgroundLuminance
);

const darker = Math.min(
foregroundLuminance,
backgroundLuminance
);

return (lighter + 0.05) / (darker + 0.05);
}

Classifying the Contrast Result

function getContrastResults(ratio) {


return {
normalTextAA: ratio >= 4.5,
largeTextAA: ratio >= 3,
normalTextAAA: ratio >= 7,
largeTextAAA: ratio >= 4.5,
nonTextAA: ratio >= 3
};
}

Formatting the Result

const ratio = contrastRatio("#003566", "#caf0f8");


const formattedRatio = `${ratio.toFixed(2)}:1`;

console.log(formattedRatio);

Normal Text Contrast

Normal text requires at least 4.5:1 for WCAG Level AA and 7:1 for Level AAA.

This category includes most paragraphs, navigation labels, button text, form labels and other text that does not meet the large-text definition.

Large Text Contrast

Large text requires at least 3:1 for Level AA and 4.5:1 for Level AAA.

Do not assume text qualifies as large merely because it is bold. Both font size and weight must be considered.

Non-Text Contrast

Meaningful visual information in interface components and graphics may require a contrast ratio of at least 3:1 against adjacent colors.

Examples include form control boundaries, selected states, chart lines, icons and parts of graphics that users need to identify or understand.

Buttons and Form Controls

When checking a button, consider more than the label. Test:

  • The button text against the button background.
  • The button boundary against the surrounding page when the boundary is necessary.
  • The hover state.
  • The active state.
  • The keyboard focus indicator.
  • The disabled state, where applicable.

Links Inside Paragraphs

A link must remain readable against the page background. When color is the only difference between the link and surrounding text, additional contrast or another visual cue may be needed.

.content a {


color: #1d4ed8;
text-decoration: underline;
text-underline-offset: .15em;
}

Keyboard Focus Indicators

A custom focus indicator should be easy to distinguish from adjacent colors. A thick outline with a strong contrasting color is usually more reliable than a subtle shadow.

.button:focus-visible {


outline: 3px solid #111827;
outline-offset: 4px;
}

Text Over Images

A single contrast measurement may not represent an entire photograph. Text placed over an image must remain readable against every part of the image behind the letters.

A dark or light overlay can create a more predictable background.

.image-card {


background:
linear-gradient(
rgba(15, 23, 42, .2),
rgba(15, 23, 42, .88)
),
url("image.jpg") center / cover no-repeat;
color: #ffffff;
}

Text Over Gradients

Test contrast at the lightest and darkest parts of the gradient. The average gradient color is not sufficient because individual letters may appear over very different colors.

Opacity and Transparency

Contrast must be calculated from the final composited color shown on the screen. A semi-transparent text or background color cannot be evaluated correctly without including the color underneath it.

Placeholder Text

Placeholder text should not be used as the only visible label for a form field. When it is displayed, it should still be readable against the input background.

Disabled Controls

Inactive controls can be exempt from some contrast requirements, but extremely faint disabled states may still confuse users. The state should remain understandable in the context of the interface.

Dark Mode Contrast

Pure white text on pure black can provide maximum mathematical contrast, but softer near-white and dark-gray combinations may be more comfortable while still passing the required ratio.

.dark-theme {


background: #111827;
color: #f1f5f9;
}

Contrast and Color Vision Deficiencies

A passing luminance contrast ratio does not guarantee that every color distinction will be obvious. Do not communicate errors, success, status or selected states with color alone.

.error-message {


color: #b91c1c;
}

.error-message::before {
content: "Error: ";
font-weight: 700;
}

WCAG AA vs AAA

Level AA is the usual minimum target for accessible websites. Level AAA uses stricter text contrast thresholds, but not every page or piece of content is expected to satisfy every AAA success criterion.

WCAG 2.2 and Future Standards

The results in this tool should be described as WCAG 2.x contrast results. Future accessibility standards may use additional perceptual models, but draft standards should not replace the current normative WCAG 2.2 checks in a production tool.

Best Practices

  • Aim for at least 4.5:1 for normal text.
  • Use 3:1 only when the text genuinely qualifies as large.
  • Test all interactive states separately.
  • Check focus outlines against adjacent colors.
  • Test text over every part of an image or gradient.
  • Calculate transparency after colors have been composited.
  • Do not rely on color alone to communicate meaning.
  • Test colors in the actual component, not only in isolation.
  • Consider targeting AAA for important reading content when practical.

Color Contrast Checker FAQ

What is a good contrast ratio for normal text?

Normal text should have a contrast ratio of at least 4.5:1 for WCAG Level AA and 7:1 for Level AAA.

What contrast ratio is required for large text?

Large text requires at least 3:1 for Level AA and 4.5:1 for Level AAA.

What counts as large text?

Large text is generally at least 18pt regular or 14pt bold, approximately 24px regular or 18.66px bold under common CSS assumptions.

What is the highest possible contrast ratio?

The highest contrast ratio is 21:1, produced by black against white.

Do buttons need a 4.5:1 contrast ratio?

Button text generally follows the relevant text contrast requirement. Significant visual boundaries and states of the control may also need at least 3:1 against adjacent colors.

Do icons need sufficient contrast?

Meaningful icons and graphical objects may need at least 3:1 contrast when they are required to identify a control or understand information.

Can text over a gradient pass WCAG?

Yes, but the text must maintain sufficient contrast against every part of the gradient directly behind it.

Does opacity affect contrast?

Yes. The final composited foreground and background colors must be used in the calculation.

Is WCAG AA or AAA required?

Level AA is the common accessibility target. Level AAA provides stricter text contrast requirements but is not typically required for every page and every type of content.

Last update: 17. 07. 2026.