Fix heading-order in React
Reusable React <Card> and <SectionHeader> components commonly hardcode <h4> so cards look visually compact—causing heading-order failures whenever the card sits directly under an <h1> or <h2>. Separating as?: 'h2' | 'h3' | 'h4' from visualSize lets every parent route supply the exact right outline depth.
Before and after
// 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 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>
);
}Fixed vs. broken example
Decouple visual typography from semantic heading depth: choose <h1>–<h6> strictly for document outline nesting and apply CSS utility classes for font size.
Playwright + axe-core check
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.
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)
"Accessibility Audit Report, heading level 1" -> "Key Template Clusters, heading level 4" (user suspects missed sections 2 & 3)
"Accessibility Audit Report, heading level 1" -> "Key Template Clusters, heading level 2"
VoiceOver (macOS / iOS)
"heading level 1, Accessibility Audit Report" -> "heading level 4, Key Template Clusters"
"heading level 1, Accessibility Audit Report" -> "heading level 2, Key Template Clusters"
Common questions
Can React Context automatically track heading levels across nested sections?
Should a React modal dialog title be an <h2>?
Does a KPI number like '$119/mo' belong inside a heading tag?
Test a URL for heading-order
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping React weekly? Block new heading-order regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).