$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
AccessibilitybeginnerNew

Color Contrast

Share

Fix color contrast issues

Works with OpenClaude

You are an accessibility specialist. The user wants to fix color contrast issues in their web application to meet WCAG standards.

What to check first

  • Run your HTML/CSS through WebAIM's contrast checker or use npm install --save-dev axe-core to detect contrast violations
  • Identify which text/background color pairs fail (use browser DevTools → Accessibility panel or axe DevTools extension)
  • Check your current WCAG level target: AA requires 4.5:1 for normal text, 3:1 for large text; AAA requires 7:1 and 4.5:1

Steps

  1. Calculate the relative luminance of your foreground and background colors using the WCAG formula: (0.299 × R + 0.587 × G + 0.114 × B) / 255
  2. Convert RGB values to sRGB (divide by 255) and apply gamma correction using if (value <= 0.03928) then value / 12.92 else ((value + 0.055) / 1.055) ^ 2.4
  3. Compute contrast ratio: (L1 + 0.05) / (L2 + 0.05) where L1 is lighter luminance and L2 is darker
  4. Use npm install contrast-ratio or build a utility function to automate these calculations for your color pairs
  5. Audit text elements using getComputedStyle(element).color and getComputedStyle(element).backgroundColor in DevTools console
  6. Adjust color values: lighten dark backgrounds or darken light text to increase contrast
  7. Test with accessibility tools like axe, WAVE, or Lighthouse to verify 4.5:1 minimum ratio achieved
  8. Document color pairs in a design system token file (JSON, CSS custom properties, or Figma) to prevent future violations

Code

// Utility function to calculate WCAG contrast ratio
function getContrastRatio(rgb1, rgb2) {
  // Convert "rgb(r, g, b)" or "#hex" to [r, g, b]
  const toRGB = (color) => {
    if (color.startsWith('#')) {
      const hex = color.slice(1);
      return [
        parseInt(hex.substr(0, 2), 16),
        parseInt(hex.substr(2, 2), 16),
        parseInt(hex.substr(4, 2), 16)
      ];
    }
    return color.match(/\d+/g).map(Number);
  };

  // Calculate relative luminance
  const getLuminance = (rgb) => {
    const [r, g, b] = rgb.map(val => {
      const v = val / 255;
      return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
    });
    return

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Auto-generated alt text from filenames — always describe the actual image content, not the filename
  • Using aria-hidden="true" on focusable elements — the element will still receive focus but be invisible to screen readers, breaking keyboard navigation
  • Color contrast ratios that pass on the design file but fail in production due to anti-aliasing or font weight differences
  • Adding ARIA labels to elements that already have semantic HTML — this often confuses screen readers more than it helps
  • Skipping the lang attribute on the <html> element — screen readers won't pronounce content correctly without it

When NOT to Use This Skill

  • When your component is purely decorative and not part of the user-interactive flow
  • When you're prototyping and the design will change significantly — wait until the design stabilizes
  • On third-party embeds where you can't modify the markup (use a wrapper-level fix instead)

How to Verify It Worked

  • Run axe DevTools browser extension on the page — should show 0 violations
  • Test with a screen reader (VoiceOver on Mac, NVDA on Windows) — every interactive element should be announced clearly
  • Navigate the entire flow using only the Tab key — you should be able to reach and activate every interactive element
  • Check Lighthouse accessibility score — should be 95+ for production

Production Considerations

  • Add accessibility tests to your CI pipeline so regressions don't ship — fail the build on critical violations
  • Real users with disabilities navigate differently than automated tools — schedule manual testing with disabled users at least once per quarter
  • WCAG 2.1 AA is the legal minimum in most jurisdictions (ADA, EAA). AAA is aspirational, not required
  • Document your accessibility decisions in a public a11y statement — required for ADA compliance in the US

Quick Info

Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
accessibilitycolorcontrast

Install command:

curl -o ~/.claude/skills/color-contrast.md https://claude-skills-hub.vercel.app/skills/accessibility/color-contrast.md

Related Accessibility Skills

Other Claude Code skills in the same category — free to download.

Want a Accessibility skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.