My pricing page had the usual monthly/yearly toggle: a pill with a sliding knob between the words "Monthly" and "Yearly". It worked with a mouse. Then I printed Chromium's accessibility tree for it with Playwright:

- main: - text: Monthly - button - text: Yearly - paragraph: $29/month 

A button with no name and no state. Someone using a screen reader hears "button" and has to guess what it does and which billing period is active.

This post rebuilds it from two native radio buttons, then walks through five traps I hit while testing. Everything below was built with next build in a fresh create-next-app project and checked in Chromium with Playwright, on Next.js 16.5.0, React 19.3.1 and Tailwind CSS 4.3.3.

1. Use a radio group, not a switch

The WAI-ARIA Authoring Practices Guide (APG) defines a switch as an input for choosing "one of two values: on or off". Monthly vs yearly isn't on or off. It's a choice between two named options, which is what a radio group is for: a set of checkable buttons where only one can be checked at a time.

Native radios give you the keyboard model for free. In my Playwright run, Tab moved focus into the group once, the arrow keys moved focus and checked the next option (wrapping at the end), and the next Tab left the group. That matches the APG radio group pattern. A <fieldset> with a <legend> gives the group its name.

2. The toggle component

The plan data is a plain module:

// app/pricing/plans.ts export type Billing = "monthly" | "yearly"; export type Plan = { name: string; monthly: number; // per month, billed monthly yearly: number; // per month, billed yearly }; export const plans: Plan[] = [ { name: "Starter", monthly: 12, yearly: 10 }, { name: "Pro", monthly: 29, yearly: 24 }, ]; 

The toggle:

// app/pricing/billing-toggle.tsx "use client"; import { useId } from "react"; import type { Billing } from "./plans"; const options: { value: Billing; label: string }[] = [ { value: "monthly", label: "Monthly" }, { value: "yearly", label: "Yearly (2 months free)" }, ]; export function BillingToggle({ value, onChange, }: { value: Billing; onChange: (value: Billing) => void; }) { const name = useId(); return ( <fieldset className="inline-flex gap-1 rounded-full border border-gray-300 p-1"> <legend className="sr-only">Billing period</legend> {options.map((option) => ( <label key={option.value} className="cursor-pointer rounded-full px-4 py-2 text-sm has-checked:bg-gray-900 has-checked:text-white has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-blue-600" > <input type="radio" name={name} value={option.value} checked={value === option.value} onChange={() => onChange(option.value)} className="sr-only" /> {option.label} </label> ))} </fieldset> ); } 

A few details:

  • Each input sits inside its <label>, so there's no id or htmlFor to manage.
  • sr-only hides the input visually but keeps it in the accessibility tree and the tab order.
  • has-checked: styles the label when its input is checked. In the built CSS it compiles to :has(:checked).
  • useId() gives each toggle instance its own name. Section 6 shows why that matters.

3. Wire it to the price cards

One Client Component holds the state and renders the toggle and the cards:

// app/pricing/pricing.tsx "use client"; import { useState } from "react"; import { BillingToggle } from "./billing-toggle"; import type { Billing, Plan } from "./plans"; export function Pricing({ plans, initial = "monthly", }: { plans: Plan[]; initial?: Billing; }) { const [billing, setBilling] = useState<Billing>(initial); return ( <section className="mt-8"> <BillingToggle value={billing} onChange={setBilling} /> <div className="mt-8 grid gap-6 sm:grid-cols-2"> {plans.map((plan) => ( <article key={plan.name} className="rounded-2xl border border-gray-200 p-6"> <h2 className="text-lg font-semibold">{plan.name}</h2> <p className="mt-4 text-4xl font-bold"> ${billing === "monthly" ? plan.monthly : plan.yearly} <span className="text-base font-normal"> /month</span> </p> <p className="text-sm text-gray-600"> {billing === "monthly" ? "Billed monthly" : `Billed $${plan.yearly * 12} yearly`} </p> </article> ))} </div> </section> ); } 

The page stays a Server Component:

// app/pricing/page.tsx import { Pricing } from "./pricing"; import { plans } from "./plans"; export default function PricingPage() { return ( <main className="mx-auto max-w-3xl p-8"> <h1 className="text-3xl font-bold">Pricing</h1> <Pricing plans={plans} /> </main> ); } 

next build listed /pricing as ○ (Static), and the prerendered HTML already contained the monthly prices. The accessibility tree now reads:

- main: - heading "Pricing" [level=1] - group "Billing period": - text: Billing period - radio "Monthly" [checked] - text: Monthly - radio "Yearly (2 months free)" - text: Yearly (2 months free) - article: - heading "Starter" [level=2] - paragraph: $12 /month - paragraph: Billed monthly - article: - heading "Pro" [level=2] - paragraph: $29 /month - paragraph: Billed monthly 

4. Trap: hidden on the input removes it from the keyboard

My first version used className="hidden" on the inputs instead of sr-only. Mouse clicks still worked, because clicking a label checks its radio even when the input is display: none. So a click test passed.

The keyboard test didn't. I put a link before and after the toggle and pressed Tab from the first one: focus went straight to the second link. The radios were gone from the accessibility tree:

- main: - link "Before": - /url: "#" - group "Billing period": Billing period Monthly Yearly (2 months free) - link "After": - /url: "#" 

Tailwind's hidden compiles to display: none. Use sr-only for inputs you style through their label.

5. Trap: the focus ring disappears with the input

sr-only turns the input into a 1×1 px box with clip-path: inset(50%). The input still gets focus, but you can't see it. I took two screenshots of a toggle without the has-focus-visible: classes, one with a radio focused from the keyboard and one after blurring it. They were pixel-identical.

The fix draws the ring on the label instead:

has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-blue-600 

Tailwind 4 compiles these to selectors like .has-focus-visible\:outline-2:has(:focus-visible). After a Tab, the label's computed outline was solid 2px. After a mouse click it was none, because Chromium didn't match :focus-visible on the click. Keyboard users get a ring, mouse users don't.

6. Trap: two toggles with one hard-coded name

Long pricing pages often show the toggle twice, for example above the cards and above a comparison table, both bound to the same state. I tested a copy of the component with name="billing" hard-coded. A radio group is defined by a shared name, so all four radios became one group:

initial: top: monthly=false, yearly=false | bottom: monthly=true, yearly=false after clicking bottom Yearly: top: monthly=false, yearly=true | bottom: monthly=false, yearly=false | state: yearly 

On load, the top toggle had nothing checked. After a click, the bottom one had nothing checked. The arrow keys also walked out of the top toggle and into the bottom one. The browser keeps only one checked radio per group, so the two toggles keep unchecking each other.

With useId(), both toggles stayed in sync and the arrow keys wrapped inside each one. React's useId docs make the same point about hard-coded IDs: a component may be rendered more than once on a page.

7. Trap: ?billing=yearly fails the build

I wanted links like /pricing?billing=yearly to open on yearly prices, so I read the param in a Client Component:

// app/pricing/pricing-from-url.tsx "use client"; import { useSearchParams } from "next/navigation"; import { Pricing } from "./pricing"; import type { Plan } from "./plans"; export function PricingFromUrl({ plans }: { plans: Plan[] }) { const billing = useSearchParams().get("billing") === "yearly" ? "yearly" : "monthly"; return <Pricing key={billing} plans={plans} initial={billing} />; } 

With the page rendering <PricingFromUrl plans={plans} /> directly, next build failed. A fresh create-next-app on 16.5 sets cacheComponents: true in next.config.ts, and the error was:

Error: Route "/pricing": Next.js encountered URL data `useSearchParams()` in a Client Component outside of `<Suspense>`. This blocks prerendering because the value is only available at runtime. Ways to fix this: - [stream] Wrap the component in `<Suspense fallback={...}>` so the hook value streams in after prerendering - [block] Set `export const instant = false` to allow a blocking route Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook 

With cacheComponents: false, the same code failed with the older message:

⨯ useSearchParams() should be wrapped in a suspense boundary at page "/pricing". Read more: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout 

The fix works for both. Wrap it in <Suspense> and use the monthly table as the fallback:

// app/pricing/page.tsx import { Suspense } from "react"; import { Pricing } from "./pricing"; import { PricingFromUrl } from "./pricing-from-url"; import { plans } from "./plans"; export default function PricingPage() { return ( <main className="mx-auto max-w-3xl p-8"> <h1 className="text-3xl font-bold">Pricing</h1> <Suspense fallback={<Pricing plans={plans} />}> <PricingFromUrl plans={plans} /> </Suspense> </main> ); } 

The fallback has the same shape as the final table, which the Next.js docs recommend to avoid a layout shift. Both builds passed and /pricing stayed ○ (Static).

One trade-off: the prerendered HTML is the fallback. Fetching /pricing?billing=yearly with curl returned "Billed monthly". The yearly prices appear after hydration. If that matters to you, the Next.js guide "Preventing flash before hydration" covers an inline-script approach. I didn't test it here.

8. Trap: the URL changes, the prices don't

That key={billing} in PricingFromUrl is there because of this test. I added a <Link href="/pricing?billing=yearly"> banner to the layout, opened /pricing, and clicked it. Without the key, the URL changed to ?billing=yearly, but the cards kept "Billed monthly".

React's useState docs say the initial value "is ignored after the initial render". A navigation inside the same route doesn't remount Pricing, so its state stays. A key that changes with the param makes React create a fresh Pricing. With the key, the same click showed "Billed $120 yearly", and the Back button went back to monthly.

Wrap-up

  1. Use native radios in a fieldset with a legend, not a switch.
  2. Hide the inputs with sr-only, never hidden.
  3. Draw the focus ring on the label with has-focus-visible:.
  4. Give each toggle its own name with useId().
  5. Wrap useSearchParams() in <Suspense> with a same-shape fallback.
  6. Add a key when URL data seeds useState.

What I didn't test: real screen readers. I checked Chromium's accessibility tree, not NVDA or VoiceOver output.

Does your pricing page remember the billing period in the URL, or does it always start on monthly?

I keep launch checks like these as free, MIT-licensed agent skills for Claude Code, Cursor and Codex: npx skills add nandot12/nextjs-launch-skills · GitHub