React fix

Before and after

Broken — before
// Broken React component: missing alt attribute on informative product photo
export function ProductThumbnail({ src, title }: { src: string; title: string }) {
  return (
    <figure>
      <img src={src} width={320} height={240} className="rounded-md" />
      <figcaption>{title}</figcaption>
    </figure>
  );
}
Fixed — after
// Fixed React AccessibleImage: requires either descriptive alt or explicit decorative flag
type AccessibleImageProps =
  | { src: string; alt: string; decorative?: false; width: number; height: number; className?: string }
  | { src: string; decorative: true; alt?: never; width: number; height: number; className?: string };

export function AccessibleImage(props: AccessibleImageProps) {
  return (
    <img
      src={props.src}
      alt={props.decorative ? "" : props.alt}
      aria-hidden={props.decorative ? true : undefined}
      width={props.width}
      height={props.height}
      className={props.className}
    />
  );
}
Live preview

Fixed vs. broken example

Passes image-alt
Accessibility tree: role="img", accessible name="Cobalt blue stoneware ceramic pour-over mug with matte handle"

Always provide meaningful alt text for informative photos and explicitly set alt="" (empty string) for purely decorative flourishes so screen readers skip them cleanly.

Automated test

Playwright + axe-core check

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

test("React catalog thumbnails pass axe-core image-alt", async ({ page }) => {
  await page.goto("/catalog");
  const results = await new AxeBuilder({ page })
    .withRules(["image-alt"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

One shared <ProductThumbnail /> or <UserAvatar /> missing alt propagates across every list row and detail route. A11yDrift clusters every duplicate page alert back to that single React component.

Screen readers

What NVDA and VoiceOver announce

When an informative image lacks an alt attribute, screen readers either skip it silently or read out raw CDN filenames and hashes, blocking blind shoppers and readers from understanding products, charts, and editorial photos.

NVDA (Windows)

Broken

"graphic, cdn_shop_files_IMG_8842_v1731942.webp" (or skipped silently depending on verbosity)


Fixed

"Cobalt blue stoneware ceramic pour-over mug with matte handle, graphic"

VoiceOver (macOS / iOS)

Broken

"IMG_8842_v1731942.webp, image"


Fixed

"Cobalt blue stoneware ceramic pour-over mug with matte handle, image"

Common questions

Why avoid phrases like 'Image of' or 'Photo of' inside React alt strings?
NVDA and VoiceOver already announce the role ('graphic' or 'image'). Prefixing with 'Image of a mug' produces redundant speech ('Image of a mug, graphic').
How should inline SVG charts or icons be labeled in React?
Decorative SVGs need aria-hidden='true' focusable='false'. Informative standalone SVGs (such as a logo or chart) should carry role='img' and an aria-label (or a <title> referenced by aria-labelledby).
What if a user avatar sits immediately beside the user's visible full name?
Mark the avatar decorative (alt="") when the adjacent visible text already identifies the person, avoiding repetitive announcements like 'Maya Lin, graphic, Maya Lin'.