React fix

Before and after

Broken — before
// Broken React component: low-contrast muted caption & pale badge
interface ShippingNoticeProps {
  thresholdUsd: number;
}

export function ShippingNotice({ thresholdUsd }: ShippingNoticeProps) {
  return (
    <div style={{ backgroundColor: "#f9fafb", padding: "1rem" }}>
      <span style={{ backgroundColor: "#34d399", color: "#ffffff", padding: "2px 8px", borderRadius: 4 }}>
        In Stock
      </span>
      <p style={{ color: "#9ca3af", fontSize: "0.875rem", marginTop: "0.5rem" }}>
        Free shipping on orders over ${thresholdUsd}.
      </p>
    </div>
  );
}
Fixed — after
// Fixed React component: verified AA contrast tokens (5.48:1 badge, 9.86:1 text)
const CONTRAST_TOKENS = {
  surface: "#f9fafb",
  textSecondary: "#374151",
  badgeSuccessBg: "#047857",
  badgeSuccessFg: "#ffffff",
} as const;

interface ShippingNoticeProps {
  thresholdUsd: number;
}

export function ShippingNotice({ thresholdUsd }: ShippingNoticeProps) {
  return (
    <div style={{ backgroundColor: CONTRAST_TOKENS.surface, padding: "1rem" }}>
      <span
        style={{
          backgroundColor: CONTRAST_TOKENS.badgeSuccessBg,
          color: CONTRAST_TOKENS.badgeSuccessFg,
          padding: "2px 8px",
          borderRadius: 4,
          fontWeight: 600,
        }}
      >
        In Stock
      </span>
      <p style={{ color: CONTRAST_TOKENS.textSecondary, fontSize: "0.875rem", marginTop: "0.5rem" }}>
        Free shipping on orders over ${thresholdUsd}.
      </p>
    </div>
  );
}
Live preview

Fixed vs. broken example

Passes color-contrastContrast: 7.58:1 body / 5.93:1 CTA (Passes 4.5:1 AA)
Accessibility tree: paragraph "Free shipping..." (#475569 on #ffffff = 7.58:1 PASS AAA) · button "Add to Cart" (#ffffff on #0369a1 = 5.93:1 PASS AA)

Inspect the foreground and background colors in Chrome DevTools Color Picker to verify the live WCAG AA (4.5:1 normal text, 3:1 large text) contrast badges.

Automated test

Playwright + axe-core check

tests/a11y-color-contrast.spec.ts
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

test("React checkout & shipping notices meet 4.5:1 contrast", async ({ page }) => {
  await page.goto("/checkout");
  await page.waitForSelector("[data-testid='shipping-notice']");
  const results = await new AxeBuilder({ page })
    .withRules(["color-contrast"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A low-contrast <StatusBadge /> or <FormHelperText /> reused across 40 React routes produces dozens of duplicate page errors. A11yDrift normalizes CSS-module hashes (e.g. .Badge_muted__3xK9p) so all occurrences merge into a single component cluster.

Who this affects

Low-vision readers, older users with presbyopia, people with color-vision deficiencies, and anyone viewing a screen in bright sunlight struggle or fail to read muted gray captions, pale badges, and low-contrast CTA buttons.

NVDA & VoiceOver transcript

Screen readers announce the same copy for both versions; this rule primarily impacts low-vision readers, screen magnifiers, and visual legibility.

NVDA (Windows)

Broken

Screen readers still speak "Free shipping on orders over $75" and "Add to Cart, button", but screen magnifier and low-vision users cannot visually locate or read the faded copy and pale blue button.


Fixed

Screen readers announce "Free shipping on orders over $75" and "Add to Cart, button", while sighted low-vision and ZoomText users clearly distinguish both the 7.58:1 body copy and 5.93:1 CTA.

VoiceOver (macOS / iOS)

Broken

VoiceOver speaks "Add to Cart, button", yet users combining VoiceOver with Zoom or macOS Increase Contrast experience severe glare washout on the 2.14:1 sky-blue fill.


Fixed

VoiceOver speaks "Add to Cart, button", and the 5.93:1 darkened surface stays legible across macOS Zoom, mobile sunlight, and high-brightness displays.

Common questions

Why does axe-core flag my React text even though my base color is dark?
CSS opacity on a parent wrapper or alpha-channel text colors (rgba) blend with the underlying background. axe-core measures the final composited pixel ratio, so a #0f172a string inside an opacity: 0.4 container fails 4.5:1.
Are disabled React buttons exempt from WCAG 1.4.3 color-contrast?
True disabled controls (HTML disabled attribute) are technically exempt from SC 1.4.3, though aria-disabled='true' controls that remain focusable are still evaluated by axe-core and benefit from readable styling.
Can jsdom + jest-axe reliably test color-contrast in React unit tests?
No—jsdom does not run a full CSS layout/paint engine and disables axe-core's color-contrast rule by default. Always run color-contrast inside a real Chromium browser via Playwright and @axe-core/playwright.