# Gray text plus opacity: the first accessibility scan found 20 contrast failures

> My Japanese-minimal design loves soft gray text, and I habitually stack opacity on top for hierarchy. Wiring in axe-core found 20 contrast failures on the first run, one only visible with real data.

- Date: 2026-11-28
- Topics: Accessibility, Debugging
- Chinese original: https://kbs0830.com/blog/axe-opacity-contrast

This site's design direction is Japanese minimalism: lots of white space, and gray `#6b6b6b` for secondary text. The gray itself is fine: its contrast against the background is about 5:1, which passes the 4.5:1 that WCAG AA asks for.

The problem was a habit of mine: when I wanted something "even fainter", I added `opacity-60` on top of gray text.

```tsx
<p className="text-xs text-(--muted) opacity-60">{project.title}</p>
```

Gray × 60% opacity renders as a lighter color, and the contrast drops to about 2.4:1.

I had caught a contrast problem once in July when I ran Lighthouse ([that write-up](/en/blog/lighthouse-wcag-contrast)), but that was a manual run over a few pages. This time I wired axe-core into the E2E tests, so every push is checked automatically.

## How the test is written

It uses `@axe-core/playwright` to scan 8 pages, once in light and once in dark mode, and only fails on serious/critical levels:

```ts
const result = await new AxeBuilder({ page })
  .withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
  .exclude("canvas") // the 3D background is decoration
  .analyze();
```

Two details:

- **Turn on "reduce motion"**: text on this site fades in as you scroll to it, so it starts at opacity 0. If the animation is not turned off, axe treats text that has not faded in yet as low contrast.
- **Switch through the home page tabs one by one**: the content of unselected tabs is `hidden`, and axe does not check it.

## The first run

Of 16 combinations (8 pages × 2 themes), 8 failed. About 20 spots across the site, almost all of the same pattern:

| Where | How it was written | Contrast |
| --- | --- | --- |
| English outcome line on a project | indigo × `opacity-50` | 2.3:1 |
| Note at the bottom of the resume | gray × `opacity-60` | 2.4:1 |
| "Last updated" in the footer | gray × `opacity-70` | 2.8:1 |
| Edge labels in the dark-mode architecture diagram | `#ccc` text on `#585858` | 4.43:1 |

The last one misses by a hair: 4.43 against 4.5. That was a default of mermaid's dark theme, and darkening the label background fixed it.

It also caught one issue that was not about contrast: the home page subtitle appears character by character like a typewriter, and I had put an `aria-label` on the `<p>` so screen readers would read the whole sentence, but `<p>` does not allow `aria-label`. I replaced it with a hidden text that only screen readers see, and marked the typing animation `aria-hidden`.

## Fixed it, and CI was still red

I fixed all 20 places, all 53 local tests passed, and I pushed. The E2E run on GitHub Actions: failed.

```
/stats color-contrast (serious) × 4: ... > .opacity-60
```

The percentage numbers on the `/stats` page:

```tsx
<span className="text-xs text-(--muted)">
  {value} <span className="opacity-60">{pct}%</span>
</span>
```

The gray is on the **outer** element and `opacity-60` is on the **inner child**. In my first pass I searched for "the same line has both `text-(--muted)` and `opacity-`", and this way of writing it did not match.

So why did it pass locally? I had tested in a separate clean folder (so installing new packages would not affect the live site), and that folder has no traffic data, so that part of `/stats` is not shown at all. CI runs in the folder with real data, where that part appears, and got caught.

## What I learned

- **Fade text with font size and color, not with opacity.** Opacity multiplies, so the gray you see in the design is not the color the user actually sees.
- **An automated check can only check what is on screen.** Collapsed tabs and sections that only show up when there is data both need a way to be made visible.
- **When test data differs from production data, results can differ.** This time it happened that CI used real data and caught it; the opposite case surely exists too.

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/axe-opacity-contrast
