Fix aria-valid-attr-value in Next.js
Next.js App Router layouts often trip aria-valid-attr-value when a mobile drawer button sets aria-controls='mobile-nav' before the lazy-loaded drawer mounts, or when active nav links pass aria-current='active' instead of the valid WAI-ARIA token 'page'. Using valid WAI-ARIA 1.2 tokens and conditional IDREFs keeps both SSR HTML and hydrated DOM clean.
Before and after
// app/components/HeaderLink.tsx (Broken: "active" is not a valid aria-current token)
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
export function HeaderLink({ href, children }: { href: string; children: React.ReactNode }) {
const pathname = usePathname();
const isActive = pathname === href;
return (
<Link href={href} aria-current={isActive ? ("active" as never) : undefined}>
{children}
</Link>
);
}// app/components/HeaderLink.tsx (Fixed: valid WAI-ARIA token aria-current="page")
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
export function HeaderLink({ href, children }: { href: string; children: React.ReactNode }) {
const pathname = usePathname();
const isActive = pathname === href;
return (
<Link href={href} aria-current={isActive ? "page" : undefined}>
{children}
</Link>
);
}Fixed vs. broken example
Never interpolate unvalidated booleans, undefined IDs, or custom strings like 'open'/'closed' into ARIA attributes; only render aria-controls when the controlled ID exists in the DOM.
Playwright + axe-core check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test("Next.js header links and mobile drawers pass aria-valid-attr-value", async ({ page }) => {
await page.goto("/pricing");
await expect(page.locator('a[aria-current="page"]')).toHaveCount(1);
const results = await new AxeBuilder({ page })
.withRules(["aria-valid-attr-value"])
.analyze();
expect(results.violations).toEqual([]);
});Template deduplication tip
An invalid aria-current='active' or broken aria-controls inside app/layout.tsx fires across every page of your Next.js app. A11yDrift collapses the entire site to one header cluster so one prop fix resolves all routes.
What NVDA and VoiceOver announce
Invalid ARIA tokens (like aria-expanded='open'), broken IDREFs (aria-controls pointing to a nonexistent or unmounted ID), or mistyped booleans cause browsers and screen readers to silently drop interactive state announcements.
NVDA (Windows)
"Shipping & Returns FAQ, button" (collapsed/expanded state omitted due to invalid token)
"Shipping & Returns FAQ, button, expanded"
VoiceOver (macOS / iOS)
"Shipping & Returns FAQ, button" (state not exposed)
"Shipping & Returns FAQ, expanded, button"
Common questions
Why does next/dynamic lazy loading cause aria-controls violations in Next.js?
Can aria-labelledby point to multiple space-separated IDs in Next.js?
How do I validate ARIA attribute types in Next.js TypeScript projects?
as any or as never—@types/react already enforces exact WAI-ARIA 1.2 union types for aria-current, aria-live, aria-haspopup, and aria-sort.Test a URL for aria-valid-attr-value
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping Next.js weekly? Block new aria-valid-attr-value regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).