Fix label in Next.js
Next.js App Router landing pages and SaaS onboarding forms frequently ship placeholder-only Server Action <form action={subscribe}> fields. Associating every <input> with a <label htmlFor> (using useId() in reusable client inputs or explicit static IDs in Server Components) guarantees clean screen-reader output even before client JavaScript hydrates.
Before and after
// app/components/NewsletterForm.tsx (Broken Next.js Server Action form)
import { subscribeAction } from "@/app/actions";
export function NewsletterForm() {
return (
<form action={subscribeAction}>
<input type="email" name="email" placeholder="Your email address" required />
<button type="submit">Subscribe</button>
</form>
);
}// app/components/NewsletterForm.tsx (Fixed Server Component form with explicit label)
import { subscribeAction } from "@/app/actions";
export function NewsletterForm({ idPrefix = "footer" }: { idPrefix?: string }) {
const fieldId = `${idPrefix}-newsletter-email`;
return (
<form action={subscribeAction} className="space-y-2">
<label htmlFor={fieldId} className="block text-sm font-medium text-slate-900">
Email address
</label>
<div className="flex gap-2">
<input
id={fieldId}
type="email"
name="email"
autoComplete="email"
placeholder="alex@company.com"
required
/>
<button type="submit">Subscribe</button>
</div>
</form>
);
}Fixed vs. broken example
Click directly on the "Work email address" label in the fixed preview: native browsers expand the hit target and immediately move focus into the input.
Playwright + axe-core check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test("Next.js Server Action newsletter form passes axe-core label", async ({ page }) => {
await page.goto("/blog");
await expect(page.getByLabel("Email address")).toBeVisible();
const results = await new AxeBuilder({ page })
.withRules(["label"])
.analyze();
expect(results.violations).toEqual([]);
});Template deduplication tip
When a shared Next.js <NewsletterSignup /> component is imported inside app/layout.tsx or app/blog/layout.tsx, fixing its <label htmlFor> once clears the violation across every route segment.
What NVDA and VoiceOver announce
Placeholder-only inputs lose their hint the moment a user starts typing, cannot be focused by clicking a visible label target, and leave screen-reader and cognitive-disability users guessing which data belongs in each field during checkout or signup.
NVDA (Windows)
"edit, has auto complete, blank" (no field purpose announced)
"Work email address, edit, has auto complete, blank"
VoiceOver (macOS / iOS)
"edit text, Work email address" (inconsistent placeholder fallback that disappears once filled)
"Work email address, edit text"
Common questions
Can I call React useId() inside a Next.js Server Component?
Does Next.js Server Action progressive enhancement keep labels working without JS?
How should multi-input OTP or verification code fields be labeled in Next.js?
Test a URL for label
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping Next.js weekly? Block new label regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).