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.
Free Web Accessibility Tool
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.
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.
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.
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 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.
Dark navy or charcoal text on a pale background often provides strong contrast while appearing softer than pure black.
White or off-white text can work well on dark blue, charcoal and black backgrounds when the calculated contrast remains sufficient.
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.
Links should remain readable against their background and should not rely on color alone when they appear inside surrounding body text.
Custom keyboard focus outlines must remain distinguishable from the colors immediately beside them.
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.
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 is calculated from linearized red, green and blue channel values.
L = 0.2126 × R + 0.7152 × G + 0.0722 × B
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
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);
}
function getContrastResults(ratio) {
return {
normalTextAA: ratio >= 4.5,
largeTextAA: ratio >= 3,
normalTextAAA: ratio >= 7,
largeTextAAA: ratio >= 4.5,
nonTextAA: ratio >= 3
};
}
const ratio = contrastRatio("#003566", "#caf0f8");
const formattedRatio = `${ratio.toFixed(2)}:1`;
console.log(formattedRatio);
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 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.
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.
When checking a button, consider more than the label. Test:
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;
}
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;
}
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;
}
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.
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 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.
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.
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;
}
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;
}
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.
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.
Normal text should have a contrast ratio of at least
4.5:1 for WCAG Level AA and 7:1 for Level
AAA.
Large text requires at least 3:1 for Level AA and
4.5:1 for Level AAA.
Large text is generally at least 18pt regular or 14pt bold, approximately 24px regular or 18.66px bold under common CSS assumptions.
The highest contrast ratio is 21:1, produced by black
against white.
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.
Meaningful icons and graphical objects may need at least
3:1 contrast when they are required to identify a control
or understand information.
Yes, but the text must maintain sufficient contrast against every part of the gradient directly behind it.
Yes. The final composited foreground and background colors must be used in the calculation.
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.