# 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.

- Category: Web Platform · Published: 2026-10-29 · Updated: 2026-11-18 · Reading time: 8 min read
- Canonical URL: https://hazeui.com/guides/accessible-accordions-tabs-no-javascript-fallbacks
- Tags: progressive-enhancement, accordion, tabs, no-js, html

## Executive Summary

Accessible accordions, tabs, and mobile menus should work immediately on initial HTML render before JavaScript downloads or executes. Haze UI implements exclusive accordions using native <details name>, tabs using anchor links paired with CSS :target rules, and mobile navigation using the Popover API—upgrading cleanly to ARIA roles and sliding indicators only after script enhancement.

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:

1. A screen reader announces "Tab 1 of 3" and intercepts `ArrowRight` / `ArrowLeft` expectations.
2. Pressing `Enter` or `ArrowRight` does nothing because JavaScript has not bound yet.
3. All panels either flash unstyled at once or stay stuck behind `hidden` forever.

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](/ui/accordion), [FAQ Accordion](/blocks/faq-accordion) |
| **Collapsible region** | Native `<details>` / `<summary>` | None needed | [Collapsible](/ui/collapsible) |
| **Tab panels** | `<a href="#panel-id">` links + CSS `:target` | Upgrades to `role="tab"`, arrow keys, sliding thumb | [Tabs](/ui/tabs) |
| **Mobile navbar drawer** | `popovertarget` + `popover` attribute | None needed | [Navbar Simple](/blocks/navbar-simple) |
| **Multi-item FAQ groups** | Independent `<details>` panels per topic | None needed | [Grouped FAQ](/blocks/faq-grouped-accordion) |

## 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](/ui/accordion) animates open and shut cleanly in pure CSS:

```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](/ui/tabs) solves this in two clean stages:

1. **Static HTML baseline:** Each tab renders as a real anchor link (`<a href="#panel-id">`), and CSS uses the `:target` pseudo-class combined with `:has()` to show only the targeted panel—defaulting to the first panel when no fragment matches:

```css
/* 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.

2. **Enhanced ARIA + sliding key:** When `tabs.astro`'s small inline script runs, it sets `data-enhanced` (disabling the `:target` rules), adds `role="tablist"`, `role="tab"`, `role="tabpanel"`, `aria-controls`, `aria-selected`, keyboard `ArrowLeft` / `ArrowRight` / `Home` / `End` switching, and slides the `--tab-x` / `--tab-w` indicator 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](/blocks/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:

```astro
<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"` or `role="combobox"` in static HTML unless native behavior or immediate browser mechanics back it up.
- Confirm your animations sit inside `@supports` or `motion-safe:` / `prefers-reduced-motion` guards 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](/guides/css-customizable-select-and-native-form-controls).

## Mentioned Haze UI Entries

- [Accordion](https://hazeui.com/ui/accordion.md): List of expandable items built from an array, in three variants, with a chevron or plus icon and optional single-open behavior.
- [Tabs](https://hazeui.com/ui/tabs.md): Tab list switching panels horizontally or vertically in pill or underline style, with sizing, badges, and in-page link fallback.
- [FAQ: two-column exclusive accordion](https://hazeui.com/blocks/faq-accordion.md): Heading and support link on the left, an exclusive animated accordion of questions on the right, built on native details.
- [FAQ: grouped accordion cards](https://hazeui.com/blocks/faq-grouped-accordion.md): Question groups in responsive columns with independently controlled, animated native disclosures.
- [Collapsible](https://hazeui.com/ui/collapsible.md): One native details element in a bordered panel, with a chevron that turns when open and a panel that animates its height.
- [Navbar: simple with mobile menu](https://hazeui.com/blocks/navbar-simple.md): Sticky translucent top bar with wordmark, links, optional sign-in and a CTA from lg. Below lg a floating panel menu fades and slides in.

## Frequently Asked Questions

### 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.
