# WCAG 2.2 AA in Dark Mode: Contrast Math, Focus Rings, and Automated Playwright Checks

> Lessons from verifying 312 color contrast pairs and hundreds of live DOM states against WCAG 2.2 AA in Haze UI.

- Category: Accessibility · Published: 2026-10-08 · Updated: 2026-11-23 · Reading time: 9 min read
- Canonical URL: https://hazeui.com/guides/wcag-22-aa-contrast-dark-mode-ui-checklist
- Tags: wcag-22, accessibility, contrast, axe-core, playwright

## Executive Summary

Passing WCAG 2.2 AA in dark mode requires testing real composited surface colors—including text sitting on status tints (/8, /10, /14 opacity), focus rings across every panel background, and 24x24 px minimum target sizes. Haze UI verifies 312 dark and light token pairs programmatically via check-contrast plus full @axe-core/playwright scans across all 371 entries.

Accessibility failures in dark mode rarely happen on white headings against near-black backgrounds. They sneak into the subtle corners: status text floating over a tinted pill, a keyboard ring buried under a sticky filter bar, or a disabled setting description dimmed until nobody can read why it's disabled.

While building Haze UI's 371 components and blocks, automated checks caught several real bugs that looked completely fine to the naked eye. Below are the exact rules and automated guards we rely on so dark (and light) interfaces clear **WCAG 2.2 AA** reliably.

## 1. Test composited status tints, not just raw colors

Checking `--destructive` against `--background` is easy. What breaks in real interfaces is placing `--destructive` text inside a `bg-destructive/22` pill sitting on top of a `--popover` surface (`oklch(0.24 0 0)`).

When Haze UI's contrast check (`pnpm check:contrast`) composited every alpha-blended fill against `--background`, `--card`, `--secondary`, and `--popover`, **destructive text on `destructive/22` measured 4.37:1 on cards and 4.11:1 on popovers**—both failing WCAG 2.2 AA's 4.5:1 threshold.

The fix became a strict design token ceiling enforced across [Alert](/ui/alert), [Tag](/ui/tag), and status banners:

| Surface / component | Maximum tint alpha | Minimum contrast target | Measured in Haze UI (`check-contrast`) |
|---|---|---|---|
| **Small chips & pills (`Tag`, `Badge`)** | `/14` (`bg-destructive/14`, `bg-success/14`) | 4.5:1 for text & status label | 5.47:1+ dark, 5.56:1+ light |
| **Larger panels (`Alert`, banners)** | `/8` or `/10` | 4.5:1 for foreground + muted body | 5.84:1+ status, 6.73:1+ muted text |
| **Subtle neutral fills** | `foreground/5` or `foreground/8` | 4.5:1 text & muted text | 5.79:1+ dark, 7.13:1+ light |
| **Focus outline (`--ring`)** | Solid (`oklch 0.62` dark / `0.55` light) | 3.0:1 non-text (WCAG 1.4.11) | 3.94:1+ on every surface |
| **Checkbox / Switch / Control edges (`--border-control`)** | Solid (`oklch 0.56` dark / `0.54` light) | 3.0:1 non-text (WCAG 1.4.11) | 3.94:1+ dark, 5.06:1 light |

Today `pnpm check:contrast` checks **312 pairs across dark and light modes** on every build—never trusting eyeballs when alpha compositing changes surface luminance.

## 2. Never communicate status with color alone

Color-vision deficiency affects roughly 1 in 12 men and 1 in 200 women. In dark UIs where red, amber, and green dots appear on compact rows, relying purely on border color or dot hue fails WCAG 1.4.1 (Use of Color).

Pair every status indicator with an unmistakable secondary cue:

- Add an explicit text label ("At risk", "Healthy", "Failed") or icon inside [Alert](/ui/alert) and status badges.
- On interactive filter chips (like `/browse` group chips), render a visible `<Check />` icon alongside `aria-pressed="true"`—never rely solely on background inversion.
- Keep `aria-invalid="true"` fields paired with visible helper error text linked via `aria-describedby`.

## 3. Separate focus rings from hover feedback and composite clicks

Two focus mistakes plague modern web apps:

1. **Clipping focus rings inside `overflow-hidden` cards or tables.** Give scrollable table wrappers `focus-visible:-outline-offset-2` (inset outline) instead of an outward `outline-offset-2`, and add `relative focus-visible:z-10` on joined [Button Group](/ui/button-group) segments so adjacent buttons never slice a focused neighbor's ring in half.
2. **Highlighting whole wrappers on button clicks.** Using `focus-within:border-ring` on an [Input Group](/ui/input-group) lights up the entire box even when the user clicks an inline Clear or Copy button inside it. Use Tailwind v4's `has-[:is(input,textarea):focus-visible]:border-ring` so the composite border reacts strictly to the text field.

## 4. Keep disabled helper descriptions readable

When a [Checkbox](/ui/checkbox) or [Switch](/ui/switch) is disabled, dimming the entire component container drops the helper description below 4.5:1 contrast. Yet that description is often where you explain *why* the option is locked!

Instead of `opacity-50` on the whole wrapper, target only the visual control box and primary `<label>`:

```html
<div class="flex items-start gap-3 has-[:disabled]:[&>span]:opacity-50 has-[:disabled]:[&_label]:opacity-50">
  <!-- Control & label dim; <p id="...-description"> remains crisp and readable -->
</div>
```

## 5. Enforce WCAG 2.2 Target Size (24 × 24 px) and Focus Not Obscured

WCAG 2.2 added two rules that break older compact interfaces:

- **2.5.8 Target Size (Minimum):** Interactive buttons, close icons, pagination dots, and nav links must measure at least **24 × 24 CSS pixels** (with inline prose links inside paragraphs excepted). Every button size (`sm` is `32px`, `md` is `40px`, close buttons are at least `24px–32px`) and chip in Haze UI satisfies this on both 390 px mobile and 1280 px desktop.
- **2.4.11 Focus Not Obscured (Minimum):** When a site uses a sticky top navbar (65 px) plus a sticky filter bar (~61–105 px), pressing `Tab` or `Shift+Tab` near the top of the viewport can scroll a card link underneath the sticky bars. Measure your combined sticky stack height and set `html { scroll-padding-top: <height + 8px>; }` so focused cards and section headings always clear the header.
- **2.1.4 Character Key Shortcuts:** If your app supports single-key shortcuts (`/`, `?`, `j`, `k`), give users a visible switch (like Haze UI's Shortcuts dialog toggle) to disable single-key shortcuts without affecting `Ctrl/⌘ K`.

## 6. Wire automated `@axe-core/playwright` audits into CI

Static contrast scripts catch token errors; Playwright catches real layout, focus, and ARIA bugs in rendered pixels. Here is a minimal reusable Playwright + axe check modeled directly on Haze UI's `tests/a11y.spec.ts` and `tests/marketing.spec.ts`:

```ts
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

const TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"];

test("page passes WCAG 2.2 AA with zero overflow at 320px and 1440px", async ({ page }) => {
  for (const width of [320, 1440]) {
    await page.setViewportSize({ width, height: 900 });
    await page.goto("/");
    const overflow = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth);
    expect(overflow).toBeLessThanOrEqual(0);

    const { violations } = await new AxeBuilder({ page }).withTags(TAGS).analyze();
    expect(violations).toEqual([]);
  }
});
```

One crucial helper from our test suite: **wait for finite animations (`document.getAnimations()`) to finish before calling `axe.analyze()`**. Otherwise axe reads mid-fade opacity values during a 200 ms modal enter transition and logs false-positive contrast errors.

Explore [Alert](/ui/alert), [Command Palette](/blocks/command-palette), and [Checkbox](/ui/checkbox) to inspect these accessibility rules in source, or read [Quiet UI Motion](/guides/ui-motion-without-slop-css-easing-reduced-motion) next.

## Mentioned Haze UI Entries

- [Alert](https://hazeui.com/ui/alert.md): Inline message panel with a status icon, title, optional description and action slot, in five variants.
- [Tag](https://hazeui.com/ui/tag.md): Small pill that names a state such as Paid, Past due or Failed, in five variants and three appearances with an optional dot.
- [Input group](https://hazeui.com/ui/input-group.md): Input with a leading and trailing add-on, such as https:// or an icon, where the outer box takes the border and focus ring.
- [Checkbox](https://hazeui.com/ui/checkbox.md): A native checkbox with a label, optional description, and a mixed state for partially selected groups.
- [Switch](https://hazeui.com/ui/switch.md): On/off toggle drawn on a native checkbox with role=switch: a 36 by 20 px track and a sliding thumb, with label and description.
- [Command palette](https://hazeui.com/blocks/command-palette.md): Command palette with keyboard navigation, live filtering, native links and an event for selected actions.

## Frequently Asked Questions

### Should helper descriptions be dimmed when a checkbox or input row is disabled?

No. Users still need to read why a setting is unavailable. Dimming the description text causes automated contrast checks to fail. Haze UI dims the control box and label on disabled rows while preserving full muted-foreground contrast (6.6:1+ dark) on helper descriptions.

### How do focus-visible rings avoid sticky headers on scroll?

WCAG 2.4.11 (Focus Not Obscured) fails when keyboard Tab navigation scrolls a link beneath a sticky navbar or filter bar. Setting html { scroll-padding-top } equal to the sticky header height plus breathing room keeps focused elements unobstructed.

### What WCAG 2.2 criteria does Haze UI's Playwright suite test automatically?

Tests run @axe-core/playwright tagged with wcag2a, wcag2aa, wcag21a, wcag21aa, and wcag22aa alongside custom checks for 24x24 px target sizes, 320 px horizontal overflow, heading hierarchy, skip links, and reduced motion.
