# Site navigation

The main links of a site in a `<nav>` landmark, with the current page marked.

_Diagram: Site navigation is the list of main links in the sidebar, with the current page marked, or a short row of links in the app bar._

## Live example

### Vertical (sidebar)

```html
<nav aria-label="Sidebar example" data-nav="vertical">
  <ul>
    <li><a href="#vertical-title">Overview</a></li>
    <li>
      <details open>
        <summary>Projects</summary>
        <ul>
          <li><a href="#vertical-title" aria-current="page">Active</a></li>
          <li><a href="#vertical-title">Archived</a></li>
        </ul>
      </details>
    </li>
    <li>
      <details>
        <summary>Settings</summary>
        <ul>
          <li><a href="#vertical-title">Profile</a></li>
          <li><a href="#vertical-title">Billing</a></li>
        </ul>
      </details>
    </li>
  </ul>
</nav>
```

### Horizontal (top bar)

```html
<nav aria-label="Top bar example" data-nav="horizontal">
  <ul>
    <li><a href="#horizontal-title" aria-current="page">Home</a></li>
    <li>
      <details name="top-bar">
        <summary>Products</summary>
        <ul>
          <li><a href="#horizontal-title">Design system</a></li>
          <li><a href="#horizontal-title">Icons</a></li>
        </ul>
      </details>
    </li>
    <li>
      <details name="top-bar">
        <summary>Company</summary>
        <ul>
          <li><a href="#horizontal-title">About</a></li>
          <li><a href="#horizontal-title">Careers</a></li>
        </ul>
      </details>
    </li>
    <li><a href="#horizontal-title">Contact</a></li>
    <li><a href="#horizontal-title" data-button="primary small">Sign up</a></li>
  </ul>
</nav>
```

## Attributes

| Attribute or value | Where | Effect |
| --- | --- | --- |
| `data-nav="vertical \| horizontal"` | `<nav>` (empty means vertical) |  |
| `aria-current="page"` | the current link (native ARIA) |  |
| `aria-current="true"` | a top-level horizontal link to the current section | marked like "page" |
| `<details> / <summary>` |  | inside an `<li>` for a collapsible group; open to expand it on load, name for one-at-a-time |

### Elevation

Horizontal dropdowns use `--dui-elevation-popover` and its surface, like a popover. They open at once: native details has no open transition.

### Keyboard

| Key | Action |
| --- | --- |
| <kbd>Tab</kbd> | moves to the next link or group summary / Shift+Tab: previous |
| <kbd>Enter</kbd> / <kbd>Space</kbd> | on a summary, opens or closes the group |
| <kbd>Enter</kbd> | on a link, follows it |

## Accessibility

- Native `<details>` in place of the [APG disclosure navigation](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-navigation/), not an ARIA menu.
- [`aria-current="page"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-current) is shown with a bar, a tint and bold text ([WCAG 1.4.1](https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html)).
- Give each `<nav>` a distinct `aria-label` when there are several.
- Groups do not close on <kbd>Esc</kbd>. <kbd>Enter</kbd> on the summary does.

## Specifications

- [HTML `<nav>` element](https://html.spec.whatwg.org/multipage/sections.html#the-nav-element)
- [APG Landmark regions](https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/)
- [APG Disclosure navigation example](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-navigation/)
- [MDN `aria-current`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-current)
- [MDN `nav`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/nav)
- [WCAG F73](https://www.w3.org/WAI/WCAG22/Techniques/failures/F73)
- [APG treeview](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/)
- [WHATWG the details element](https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element)
- [WCAG Non text contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)

## See also

- [Organisms](https://domestic-ui.odonckers.dev/organisms/index.md)
- Source: [`css/components/molecules/nav.css`](https://github.com/odonckers/domestic-ui/blob/main/css/components/molecules/nav.css), [`examples/molecules/nav.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/molecules/nav.html)
- Demos: Dashboard view ([Plain HTML](https://github.com/odonckers/domestic-ui/blob/main/demos/vanilla/index.html), [React](https://github.com/odonckers/domestic-ui/blob/main/demos/react/src/DashboardPage.tsx), [Angular](https://github.com/odonckers/domestic-ui/tree/main/demos/angular/src/app/dashboard), [Astro](https://github.com/odonckers/domestic-ui/blob/main/demos/astro/src/pages/index.astro), [Vue](https://github.com/odonckers/domestic-ui/blob/main/demos/vue/src/DashboardPage.vue), [Svelte](https://github.com/odonckers/domestic-ui/blob/main/demos/svelte/src/DashboardPage.svelte)); Account settings view ([Plain HTML](https://github.com/odonckers/domestic-ui/blob/main/demos/vanilla/settings.html), [React](https://github.com/odonckers/domestic-ui/blob/main/demos/react/src/SettingsPage.tsx), [Angular](https://github.com/odonckers/domestic-ui/tree/main/demos/angular/src/app/settings), [Astro](https://github.com/odonckers/domestic-ui/blob/main/demos/astro/src/pages/settings.astro), [Vue](https://github.com/odonckers/domestic-ui/blob/main/demos/vue/src/SettingsPage.vue), [Svelte](https://github.com/odonckers/domestic-ui/blob/main/demos/svelte/src/SettingsPage.svelte)); Orders view ([Plain HTML](https://github.com/odonckers/domestic-ui/blob/main/demos/vanilla/orders.html), [React](https://github.com/odonckers/domestic-ui/blob/main/demos/react/src/OrdersPage.tsx), [Angular](https://github.com/odonckers/domestic-ui/tree/main/demos/angular/src/app/orders), [Astro](https://github.com/odonckers/domestic-ui/blob/main/demos/astro/src/pages/orders.astro), [Vue](https://github.com/odonckers/domestic-ui/blob/main/demos/vue/src/OrdersPage.vue), [Svelte](https://github.com/odonckers/domestic-ui/blob/main/demos/svelte/src/OrdersPage.svelte))

## How other systems do it

For comparison only; these are not the standard this system follows.

- Apple Human Interface Guidelines: No equivalent
- Material Design 3: No equivalent
- Vercel Geist: No equivalent
