Color Contrast and Color Independence
Ensure sufficient color contrast ratios and never use color as the sole means of conveying information
When to Use
- Choosing text and background color combinations
- Designing UI states (error, success, warning) that rely on color
- Building data visualizations, charts, or status indicators
- Reviewing designs for WCAG 2.1 AA or AAA compliance
- Supporting users with low vision or color vision deficiency
Instructions
- Meet minimum contrast ratios. WCAG 2.1 AA requires:
- Normal text (under 18pt / 24px, or under 14pt / 18.5px bold): 4.5:1 contrast ratio
- Large text (18pt+ or 14pt+ bold): 3:1 contrast ratio
- Non-text UI components (icons, borders, form controls): 3:1 against adjacent colors
/* Good — #1a1a1a on #ffffff = 17.4:1 */
.body-text {
color: #1a1a1a;
background: #ffffff;
}
/* Bad — #999999 on #ffffff = 2.8:1 (fails AA) */
.muted-text {
color: #999999;
background: #ffffff;
}
/* Acceptable for large text — #767676 on #ffffff = 4.5:1 */
.large-heading {
color: #767676;
font-size: 24px;
font-weight: bold;
}
- Never use color alone to convey information. Always pair color with a secondary indicator — text, icons, patterns, or underlines.
// Bad — only color distinguishes error from success
<span style={{ color: 'red' }}>Failed</span>
<span style={{ color: 'green' }}>Passed</span>
// Good — color + icon + text label
<span style={{ color: '#d32f2f' }}>
<ErrorIcon aria-hidden="true" /> Failed
</span>
<span style={{ color: '#2e7d32' }}>
<CheckIcon aria-hidden="true" /> Passed
</span>
- Test link visibility without relying on color alone. Links within body text should have an underline or other non-color visual distinction. If you remove underlines, ensure a 3:1 contrast ratio between link color and surrounding text color.
/* Safe — underline present */
a {
color: #005fcc;
text-decoration: underline;
}
/* Also safe — 3:1 contrast between link color and body text color, plus underline on hover/focus */
a {
color: #005fcc;
text-decoration: none;
}
a:hover,
a:focus {
text-decoration: underline;
}
- Design form validation with multiple cues. Do not rely solely on a red border to indicate errors. Add an error message, an icon, or both.
<div>
<label htmlFor="email">Email</label>
<input
id="email"
aria-invalid={!!error}
aria-describedby={error ? 'email-error' : undefined}
style={{ borderColor: error ? '#d32f2f' : '#ccc' }}
/>
{error && (
<p id="email-error" role="alert" style={{ color: '#d32f2f' }}>
<ErrorIcon aria-hidden="true" /> {error}
</p>
)}
</div>
Use patterns, shapes, or labels in data visualizations. Charts with color-coded series are unreadable for color-blind users. Add patterns, direct labels, or shape markers.
Check contrast for all interactive states. Hover, focus, active, disabled, and selected states all need to meet contrast requirements against their backgrounds.
Test with simulated color vision deficiency. Chrome DevTools > Rendering > Emulate vision deficiencies. Test with protanopia, deuteranopia, tritanopia, and achromatopsia.
Design high-contrast mode support. Windows High Contrast Mode overrides your colors. Use forced-colors media query to ensure readability.
@media (forced-colors: active) {
.custom-checkbox {
border: 2px solid ButtonText;
}
}
Details
WCAG contrast levels:
- AA (minimum): 4.5:1 for normal text, 3:1 for large text and UI components
- AAA (enhanced): 7:1 for normal text, 4.5:1 for large text
- Target AA for all projects; target AAA for government, healthcare, and financial applications
Contrast ratio formula: Based on relative luminance of the two colors. Use tools to calculate — do not eyeball it.
Recommended tools:
- Browser DevTools: Hover over elements to see contrast ratio in the color picker
- WebAIM Contrast Checker: https://webaim.org/resources/contrastchecker/
- axe DevTools: Flags contrast violations automatically
- Stark (Figma plugin): Check contrast during design
Color-blind-safe palettes: Approximately 8% of males and 0.5% of females have color vision deficiency. Red-green is the most common. Avoid red/green as the only distinction. Blue/orange is generally safe across all types.
Common mistakes:
- Placeholder text with insufficient contrast (often fails AA)
- Disabled states that are indistinguishable from enabled states
- Focus indicators that disappear against the background
- Charts using red, green, and yellow without patterns or labels
Source
https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.
1---2name: a11y-color-contrast3description: Color Contrast and Color Independence4metadata:5 source: https://skillmd.com/skills/intense-visions/a11y-color-contrast6---7# Color Contrast and Color Independence89> Ensure sufficient color contrast ratios and never use color as the sole means of conveying information1011## When to Use1213- Choosing text and background color combinations14- Designing UI states (error, success, warning) that rely on color15- Building data visualizations, charts, or status indicators16- Reviewing designs for WCAG 2.1 AA or AAA compliance17- Supporting users with low vision or color vision deficiency1819## Instructions20211. **Meet minimum contrast ratios.** WCAG 2.1 AA requires:22 - **Normal text** (under 18pt / 24px, or under 14pt / 18.5px bold): **4.5:1** contrast ratio23 - **Large text** (18pt+ or 14pt+ bold): **3:1** contrast ratio24 - **Non-text UI components** (icons, borders, form controls): **3:1** against adjacent colors2526```css27/* Good — #1a1a1a on #ffffff = 17.4:1 */28.body-text {29 color: #1a1a1a;30 background: #ffffff;31}3233/* Bad — #999999 on #ffffff = 2.8:1 (fails AA) */34.muted-text {35 color: #999999;36 background: #ffffff;37}3839/* Acceptable for large text — #767676 on #ffffff = 4.5:1 */40.large-heading {41 color: #767676;42 font-size: 24px;43 font-weight: bold;44}45```46472. **Never use color alone to convey information.** Always pair color with a secondary indicator — text, icons, patterns, or underlines.4849```tsx50// Bad — only color distinguishes error from success51<span style={{ color: 'red' }}>Failed</span>52<span style={{ color: 'green' }}>Passed</span>5354// Good — color + icon + text label55<span style={{ color: '#d32f2f' }}>56 <ErrorIcon aria-hidden="true" /> Failed57</span>58<span style={{ color: '#2e7d32' }}>59 <CheckIcon aria-hidden="true" /> Passed60</span>61```62633. **Test link visibility without relying on color alone.** Links within body text should have an underline or other non-color visual distinction. If you remove underlines, ensure a 3:1 contrast ratio between link color and surrounding text color.6465```css66/* Safe — underline present */67a {68 color: #005fcc;69 text-decoration: underline;70}7172/* Also safe — 3:1 contrast between link color and body text color, plus underline on hover/focus */73a {74 color: #005fcc;75 text-decoration: none;76}77a:hover,78a:focus {79 text-decoration: underline;80}81```82834. **Design form validation with multiple cues.** Do not rely solely on a red border to indicate errors. Add an error message, an icon, or both.8485```tsx86<div>87 <label htmlFor="email">Email</label>88 <input89 id="email"90 aria-invalid={!!error}91 aria-describedby={error ? 'email-error' : undefined}92 style={{ borderColor: error ? '#d32f2f' : '#ccc' }}93 />94 {error && (95 <p id="email-error" role="alert" style={{ color: '#d32f2f' }}>96 <ErrorIcon aria-hidden="true" /> {error}97 </p>98 )}99</div>100```1011025. **Use patterns, shapes, or labels in data visualizations.** Charts with color-coded series are unreadable for color-blind users. Add patterns, direct labels, or shape markers.1031046. **Check contrast for all interactive states.** Hover, focus, active, disabled, and selected states all need to meet contrast requirements against their backgrounds.1051067. **Test with simulated color vision deficiency.** Chrome DevTools > Rendering > Emulate vision deficiencies. Test with protanopia, deuteranopia, tritanopia, and achromatopsia.1071088. **Design high-contrast mode support.** Windows High Contrast Mode overrides your colors. Use `forced-colors` media query to ensure readability.109110```css111@media (forced-colors: active) {112 .custom-checkbox {113 border: 2px solid ButtonText;114 }115}116```117118## Details119120**WCAG contrast levels:**121122- **AA (minimum):** 4.5:1 for normal text, 3:1 for large text and UI components123- **AAA (enhanced):** 7:1 for normal text, 4.5:1 for large text124- Target AA for all projects; target AAA for government, healthcare, and financial applications125126**Contrast ratio formula:** Based on relative luminance of the two colors. Use tools to calculate — do not eyeball it.127128**Recommended tools:**129130- Browser DevTools: Hover over elements to see contrast ratio in the color picker131- WebAIM Contrast Checker: https://webaim.org/resources/contrastchecker/132- axe DevTools: Flags contrast violations automatically133- Stark (Figma plugin): Check contrast during design134135**Color-blind-safe palettes:** Approximately 8% of males and 0.5% of females have color vision deficiency. Red-green is the most common. Avoid red/green as the only distinction. Blue/orange is generally safe across all types.136137**Common mistakes:**138139- Placeholder text with insufficient contrast (often fails AA)140- Disabled states that are indistinguishable from enabled states141- Focus indicators that disappear against the background142- Charts using red, green, and yellow without patterns or labels143144## Source145146https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum147148## Process1491501. Read the instructions and examples in this document.1512. Apply the patterns to your implementation, adapting to your specific context.1523. Verify your implementation against the details and edge cases listed above.153154## Harness Integration155156- **Type:** knowledge — this skill is a reference document, not a procedural workflow.157- **No tools or state** — consumed as context by other skills and agents.158159## Success Criteria160161- The patterns described in this document are applied correctly in the implementation.162- Edge cases and anti-patterns listed in this document are avoided.