Tailwind CSS fix

Before and after

Broken — before
<!-- Broken Tailwind CSS: slate-400 on white (2.56:1) & white on sky-400 (2.14:1) -->
<div class="rounded-lg border border-slate-200 bg-white p-4">
  <p class="mb-3 text-sm text-slate-400">
    Free shipping on orders over $75 — ships within 24 hours.
  </p>
  <button
    type="button"
    class="rounded-md bg-sky-400 px-4 py-2 text-sm font-semibold text-white hover:bg-sky-500"
  >
    Add to Cart
  </button>
</div>
Fixed — after
<!-- Fixed Tailwind CSS: slate-600 on white (7.58:1) & white on sky-700 (5.93:1) -->
<div class="rounded-lg border border-slate-300 bg-white p-4">
  <p class="mb-3 text-sm text-slate-600">
    Free shipping on orders over $75 — ships within 24 hours.
  </p>
  <button
    type="button"
    class="rounded-md bg-sky-700 px-4 py-2 text-sm font-semibold text-white hover:bg-sky-800 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-700"
  >
    Add to Cart
  </button>
</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("Tailwind product card passes axe-core color-contrast", async ({ page }) => {
  await page.goto("/pricing");
  const results = await new AxeBuilder({ page })
    .withRules(["color-contrast"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A single muted utility class like text-slate-400 in a shared card, footer, or Tailwind @theme token can trigger hundreds of raw axe-core violations across /products/* and /blog/*. A11yDrift collapses those into one root template cluster so upgrading your semantic color token fixes the entire site in one PR.

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

Which Tailwind gray/slate shades safely pass 4.5:1 on white?
On a pure #ffffff surface, text-slate-500 (#64748b) sits right near 4.76:1 while text-slate-600 (#475569) reaches 7.58:1. Use 600 or darker for body/helper text so it also passes on tinted surfaces like bg-slate-50.
Why do Tailwind bg-emerald-500 and bg-sky-500 fail with text-white?
Mid-spectrum hues like sky-500 (#0ea5e9) and emerald-500 (#10b981) have high relative luminance, dropping white text below 3.1:1. Either darken the fill to bg-sky-700 / bg-emerald-700 or switch the foreground to text-slate-950.
How do I prevent Tailwind contrast regressions in CI?
Define semantic tokens in tailwind.config.ts or Tailwind v4 @theme (--color-muted, --color-primary-bg) and gate pull requests with Playwright + @axe-core/playwright running color-contrast on key routes.

Fix color-contrast in other stacks

More Tailwind CSS guides