惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
阮一峰的网络日志
阮一峰的网络日志
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
罗磊的独立博客
S
SegmentFault 最新的问题
V
V2EX
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
D
Docker
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
M
Microsoft Research Blog - Microsoft Research
Martin Fowler
Martin Fowler
S
Secure Thoughts
B
Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
T
True Tiger Recordings
GbyAI
GbyAI
P
Proofpoint News Feed
P
Privacy International News Feed
Jina AI
Jina AI
The Cloudflare Blog
I
Intezer
AWS News Blog
AWS News Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Archives - TechRepublic
NISL@THU
NISL@THU
The Register - Security
The Register - Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
P
Palo Alto Networks Blog
S
Schneier on Security
L
LINUX DO - 热门话题
C
CXSECURITY Database RSS Feed - CXSecurity.com
Security Latest
Security Latest
C
Cybersecurity and Infrastructure Security Agency CISA

DEV Community

暂无文章

Color Contrast Failures: The Number One Accessibility Issue and How to Fix It
DevToolsmith · 2026-05-22 · via DEV Community

DevToolsmith

Color contrast failures are the single most common accessibility issue on the web. The WebAIM Million study found them on 83.6% of home pages tested. Yet they're also one of the easiest issues to fix — once you understand the rules.

The WCAG Contrast Requirements

WCAG 2.2 defines two success criteria for color contrast:

1.4.3 Contrast (Minimum) — Level AA

  • Normal text (< 18pt or < 14pt bold): minimum 4.5:1 contrast ratio
  • Large text (≥ 18pt or ≥ 14pt bold): minimum 3:1 contrast ratio
  • UI components and graphical objects: minimum 3:1

1.4.6 Contrast (Enhanced) — Level AAA

  • Normal text: 7:1
  • Large text: 4.5:1

The contrast ratio formula is (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter colour's relative luminance and L2 is the darker one's.

The Mathematics Behind Luminance

Relative luminance isn't just brightness — it accounts for how the human eye perceives different wavelengths:

function relativeLuminance(r, g, b) {
  const [rs, gs, bs] = [r, g, b].map(c => {
    const sRGB = c / 255;
    return sRGB <= 0.04045
      ? sRGB / 12.92
      : Math.pow((sRGB + 0.055) / 1.055, 2.4);
  });
  return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
}

function contrastRatio(hex1, hex2) {
  const lum1 = relativeLuminance(...hexToRgb(hex1));
  const lum2 = relativeLuminance(...hexToRgb(hex2));
  const [lighter, darker] = lum1 > lum2 ? [lum1, lum2] : [lum2, lum1];
  return (lighter + 0.05) / (darker + 0.05);
}

Enter fullscreen mode Exit fullscreen mode

Common Failures and Fixes

Grey text on white backgrounds

Light grey (#767676) on white is exactly 4.54:1 — barely passing. At #757575, it fails. Use #595959 or darker for safe normal text.

Blue links on coloured backgrounds

Many design systems use brand blue (#0066CC) as the link colour. On a dark navy background (#003366), that's only 2.6:1 — a clear failure.

Placeholder text

Placeholder text is treated as normal text for contrast purposes. The typical grey placeholder on a white input (#B0B0B0 on #FFFFFF) is 2.5:1 — fails badly.

/* ❌ Fails WCAG */
input::placeholder { color: #B0B0B0; }

/* ✅ Passes WCAG AA */
input::placeholder { color: #767676; }

Enter fullscreen mode Exit fullscreen mode

Disabled states

Disabled controls are exempt from contrast requirements — but only if they're genuinely disabled (not just visually styled as disabled).

The Tricky Edge Cases

Gradients: WCAG requires the entire text background to meet contrast requirements. For text on a gradient, test at the lowest-contrast point.

Text over images: Image backgrounds change depending on the user's screen, browser rendering, and image loading. Safest approach: add a semi-transparent overlay or text shadow.

.hero-text {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  /* OR */
  background: rgba(0, 0, 0, 0.5);
  padding: 0.5em 1em;
}

Enter fullscreen mode Exit fullscreen mode

Focus indicators: WCAG 2.2 added Success Criterion 2.4.11 (Focus Appearance) — focus indicators must have at least 3:1 contrast against adjacent colours.

Automating Detection

Checking contrast manually across every combination of text and background in your app is impractical. Automated tools like AccessiScan scan your entire page across 201 WCAG 2.2 checks — including contrast — and generate a prioritised report with specific failing elements identified.

Start with Level AA compliance. The changes are usually small CSS tweaks with an outsized impact on usability for everyone, not just users with visual impairments.