Accessible Accordions, Tabs, and Menus That Work Before JavaScript Loads
How Haze UI uses <details name>, CSS :target tabs, and popover menus so core navigation works before JavaScript runs.
Every developer has tapped a hamburger button or clicked an FAQ row on a flaky connection and watched nothing happen for two full seconds. The HTML rendered, the button looked clickable, and yet the interaction sat frozen waiting on a JavaScript bundle to parse and attach event listeners.
You do not need to throw away progressive polish to fix that. You just have to build the static baseline out of real HTML semantics first, then layer ARIA roles and animated indicators on top once the script runs.
Here is how Haze UI handles accordions, tabs, and navigation menus so they work before JavaScript executes—and even when scripts never arrive.
Why fake ARIA roles break pre-hydration UX
Many component kits emit role="tablist", role="tab", and role="tabpanel" directly in server-rendered HTML, attaching click and arrow-key handlers later on mount. That creates a subtle accessibility failure during the gap between paint and hydration—or permanently if a script fails to load:
- A screen reader announces “Tab 1 of 3” and intercepts
ArrowRight/ArrowLeftexpectations. - Pressing
EnterorArrowRightdoes nothing because JavaScript has not bound yet. - All panels either flash unstyled at once or stay stuck behind
hiddenforever.
Instead, every progressive pattern in Haze UI honors one strict rule: static markup only claims behaviors the browser already handles natively.
| Pattern | Static no-JS mechanism | Progressive JS upgrade | Haze UI reference |
|---|---|---|---|
| Exclusive accordion | <details name="..."> + ::details-content |
None needed | Accordion, FAQ Accordion |
| Collapsible region | Native <details> / <summary> |
None needed | Collapsible |
| Tab panels | <a href="#panel-id"> links + CSS :target |
Upgrades to role="tab", arrow keys, sliding thumb |
Tabs |
| Mobile navbar drawer | popovertarget + popover attribute |
None needed | Navbar Simple |
| Multi-item FAQ groups | Independent <details> panels per topic |
None needed | Grouped FAQ |
Exclusive accordions with <details name> and ::details-content
Native <details> elements now support grouping via the name attribute. Give two or more <details> elements the same name="home-faq", and opening one automatically closes the others—handled natively by the browser with built-in keyboard Enter and Space toggling.
Animating height from 0 to auto used to require measuring scrollHeight in JavaScript. Using CSS interpolate-size: allow-keywords and ::details-content, Accordion animates open and shut cleanly in pure CSS:
@supports (interpolate-size: allow-keywords) {
details::details-content {
height: 0;
overflow: clip;
transition:
height 300ms cubic-bezier(0.22, 1, 0.36, 1),
content-visibility 300ms allow-discrete;
}
details[open]::details-content {
height: auto;
}
}
And what about browsers without interpolate-size: allow-keywords? Look at line 67 of accordion.astro: the inner body applies not-supports-[interpolate-size:allow-keywords]:animate-rise. Gating the fallback inside not-supports- ensures the two animation paths never run on top of each other, while prefers-reduced-motion: reduce switches ::details-content transitions down to 0.01ms.
Tabs powered by :target before JavaScript runs
Implementing tabs without breaking pre-hydration behavior is trickier than accordions because HTML has no native <tabs> element yet.
Tabs solves this in two clean stages:
- Static HTML baseline: Each tab renders as a real anchor link (
<a href="#panel-id">), and CSS uses the:targetpseudo-class combined with:has()to show only the targeted panel—defaulting to the first panel when no fragment matches:
/* Simplified selector logic used in tabs.astro before data-enhanced is set */
[data-haze-tabs]:not([data-enhanced]) [data-tabs-panels] > *:not(:first-child):not(:target):not(:has(:target)) {
display: none;
}
[data-haze-tabs]:not([data-enhanced]) [data-tabs-panels]:has(> :not(:first-child):target) > *:first-child {
display: none;
}
Without a single byte of JavaScript executing, clicking a tab updates the URL hash, displays its matching panel, hides the others, and keeps deep links shareable.
- Enhanced ARIA + sliding key: When
tabs.astro’s small inline script runs, it setsdata-enhanced(disabling the:targetrules), addsrole="tablist",role="tab",role="tabpanel",aria-controls,aria-selected, keyboardArrowLeft/ArrowRight/Home/Endswitching, and slides the--tab-x/--tab-windicator bar cleanly across tabs.
For horizontal overflowing tab rows, passing scrollable turns on edge fades and optional left/right scroll buttons—and if a scroll button hides while focused, focus automatically transfers back cleanly instead of falling onto document.body.
Mobile navigation drawers via popover
Look at how Navbar Simple opens its mobile sheet on small viewports. Instead of importing a drawer script or writing manual focus-trap state, the menu button carries popovertarget={menuId} and the mobile panel uses the native popover attribute:
<button type="button" popovertarget="site-nav-menu" aria-label="Open menu">
Menu
</button>
<div id="site-nav-menu" popover class="...">
<button type="button" popovertarget="site-nav-menu" popovertargetaction="hide" aria-label="Close menu">
Close
</button>
<!-- Navigation links -->
</div>
Our Playwright test suite (tests/keyboard.spec.ts) verifies this directly on /preview/navbar-simple at 390 px: Enter opens the menu, Escape closes it, and focus returns reliably—without requiring any custom click listener.
Practical checklist before shipping a component
Whenever you build or customize an interactive .astro primitive:
- Test the route in Chromium with JavaScript disabled in DevTools (
Ctrl+Shift+P→ Disable JavaScript). Can users still navigate tabs, open the mobile menu, and expand FAQs? - Verify you are not claiming
role="tab"orrole="combobox"in static HTML unless native behavior or immediate browser mechanics back it up. - Confirm your animations sit inside
@supportsormotion-safe:/prefers-reduced-motionguards so fallback paths never collide.
Next, see how the same native-first philosophy applies to styling native form controls with appearance: base-select, OTP inputs, and validation.
Frequently asked questions
Why shouldn't static HTML tabs include role='tablist' and role='tab' without JavaScript?
ARIA tab roles promise screen-reader users ArrowLeft/ArrowRight navigation and automatic panel hiding. If static HTML declares role='tab' before JavaScript runs—or when scripts fail—keyboard users get broken ARIA promises. Haze UI renders real in-page <a href='#id'> links statically and applies ARIA tab roles only inside the progressive enhancement script.
How do Haze UI accordions enforce only one open panel at a time without JavaScript?
Passing a shared name attribute to native <details name='group'> elements instructs the browser to close sibling details items in the same group automatically whenever a user opens another item.
How does ::details-content height animation handle older browsers?
Haze UI wraps the height: auto transition inside supports-[interpolate-size:allow-keywords]. Browsers with interpolate-size animate height smoothly; older browsers fall back to a short CSS rise animation on the inner panel without running both transitions together.
Do Haze UI mobile navigation menus work with JavaScript turned off?
Yes. Blocks like Navbar Simple trigger their mobile menu via popovertarget and popover attributes, so opening, Escape closing, and backdrop dismissal work natively with zero client JavaScript.
Components & blocks mentioned
Browse all entriesList of expandable items built from an array, in three variants, with a chevron or plus icon and optional single-open behavior.
npx shadcn@latest add @haze/accordion- TabsUI
Tab list switching panels horizontally or vertically in pill or underline style, with sizing, badges, and in-page link fallback.
npx shadcn@latest add @haze/tabs Heading and support link on the left, an exclusive animated accordion of questions on the right, built on native details.
npx shadcn@latest add @haze/faq-accordionQuestion groups in responsive columns with independently controlled, animated native disclosures.
npx shadcn@latest add @haze/faq-grouped-accordionOne native details element in a bordered panel, with a chevron that turns when open and a panel that animates its height.
npx shadcn@latest add @haze/collapsibleSticky translucent top bar with wordmark, links, optional sign-in and a CTA from lg. Below lg a floating panel menu fades and slides in.
npx shadcn@latest add @haze/navbar-simple
Continue reading
9 min read
Web Platform
Styling Native Form Controls in 2026: appearance: base-select, OTP Inputs, and Validation
9 min read
9 min read