React fix

Before and after

Broken — before
// Broken React Card: hardcodes <h4> regardless of surrounding outline depth
export function MetricCard({ title, value }: { title: string; value: string }) {
  return (
    <section className="card">
      <h4 className="text-sm font-semibold">{title}</h4>
      <p className="text-2xl font-bold">{value}</p>
    </section>
  );
}
Fixed — after
// Fixed React Card: semantic heading tag decoupled from visual typography class
type HeadingTag = "h2" | "h3" | "h4" | "h5" | "h6";

interface MetricCardProps {
  title: string;
  value: string;
  as?: HeadingTag;
}

export function MetricCard({ title, value, as: Heading = "h2" }: MetricCardProps) {
  return (
    <section className="card">
      <Heading className="text-sm font-semibold text-slate-700">{title}</Heading>
      <p className="text-2xl font-bold text-slate-950">{value}</p>
    </section>
  );
}
Live preview

Fixed vs. broken example

Passes heading-order
Accessibility tree: Sequential outline: heading level 1 -> heading level 2 (clean hierarchy)

Decouple visual typography from semantic heading depth: choose <h1>–<h6> strictly for document outline nesting and apply CSS utility classes for font size.

Automated test

Playwright + axe-core check

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

test("React dashboard metric cards preserve sequential heading-order", async ({ page }) => {
  await page.goto("/dashboard");
  const results = await new AxeBuilder({ page })
    .withRules(["heading-order"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

Refactoring one shared <SectionCard> component to accept a semantic headingLevel prop resolves skipped-heading clusters across every dashboard and marketing page.

Screen readers

What NVDA and VoiceOver announce

Over 67% of screen-reader users navigate long pages primarily by jumping between headings (H / 1–6 keys). Skipping from <h1> straight to <h4> for visual sizing breaks the mental document outline and makes sub-sections appear orphaned.

NVDA (Windows)

Broken

"Accessibility Audit Report, heading level 1" -> "Key Template Clusters, heading level 4" (user suspects missed sections 2 & 3)


Fixed

"Accessibility Audit Report, heading level 1" -> "Key Template Clusters, heading level 2"

VoiceOver (macOS / iOS)

Broken

"heading level 1, Accessibility Audit Report" -> "heading level 4, Key Template Clusters"


Fixed

"heading level 1, Accessibility Audit Report" -> "heading level 2, Key Template Clusters"

Common questions

Can React Context automatically track heading levels across nested sections?
Yes—a lightweight HeadingLevelContext that increments depth inside each <Section> allows deeply nested components to pick the right <h2>–<h6> tag automatically without manual prop drilling.
Should a React modal dialog title be an <h2>?
Yes—rendering the dialog heading as <h2> (linked via aria-labelledby on role='dialog') keeps the outline logical beneath the page <h1>.
Does a KPI number like '$119/mo' belong inside a heading tag?
No—use the heading tag for the descriptive label ('Agency Plan') and keep numeric values inside <p> or <span> elements so screen-reader heading lists stay meaningful.