# Fifteen app sidebars and when to use each

> Part of Tray UI 0.4.1, a design system in plain HTML and CSS (MIT licence). Every page: https://trayui.com/llms.txt

App sidebars in plain HTML and CSS, and which to choose: one level or two, sections that fold, a rail of icons, a file tree, a calendar, a sidebar on each side.

By Vladyslav Korzh, 18 November 2026.

A sidebar is the navigation of an application: a `<nav>` down one side, with groups of links and the current page marked. Tray UI has fifteen sidebar blocks, `sidebar-01.html` to `sidebar-15.html`, each a whole page with the sidebar in place. They are gathered on [Sidebars](https://trayui.com/blocks/sidebar.md). This article shows how they are built and when each one fits.

## The fifteen at a glance

| Block | Use it when |
| --- | --- |
| [Grouped by section](https://trayui.com/blocks/sidebar-01.md) | Every page sits one level deep, as in an admin panel. |
| [Sections that fold](https://trayui.com/blocks/sidebar-02.md) | The product has many areas and each person works in a few. |
| [A second level](https://trayui.com/blocks/sidebar-03.md) | Short lists of sub-pages are used every day. |
| [A level that folds](https://trayui.com/blocks/sidebar-04.md) | Open lists would push the column past the window. |
| [Menus](https://trayui.com/blocks/sidebar-05.md) | People go straight to one page of a section. |
| [Collapses to icons](https://trayui.com/blocks/sidebar-06.md) | Wide tables and boards need the width. |
| [Inset](https://trayui.com/blocks/sidebar-07.md) | One main area of work, with a short list of recent things. |
| [Two sidebars](https://trayui.com/blocks/sidebar-08.md) | A section is a list to pick from, such as an inbox. |
| [A file tree](https://trayui.com/blocks/sidebar-09.md) | The hierarchy is deeper than two levels. |
| [A calendar](https://trayui.com/blocks/sidebar-10.md) | The side panel filters one view instead of moving between pages. |
| [At the end](https://trayui.com/blocks/sidebar-11.md) | It is the table of contents of one long page. |
| [On each side](https://trayui.com/blocks/sidebar-12.md) | The details of the chosen record sit beside the list. |
| [Under a site header](https://trayui.com/blocks/sidebar-13.md) | Search and the account belong in one bar on every page. |
| [In a dialog](https://trayui.com/blocks/sidebar-14.md) | Settings are visited briefly, over the page. |
| [In a popover](https://trayui.com/blocks/sidebar-15.md) | The menu is opened now and then, and the screen needs its whole width. |

## The base sidebar

```html
<nav class="tray-sidebar" id="nav" aria-label="Main">
  <div class="tray-sidebar__head"><a class="tray-wordmark" href="/">Counter</a></div>
  <div class="tray-sidebar__group">
    <a class="tray-sidebar__item" href="/">…house icon…<span>Home</span></a>
    <a class="tray-sidebar__item" href="/orders" aria-current="page">
      …inbox icon…<span>Orders</span><span class="tray-badge tray-badge--count">12</span>
    </a>
  </div>
  <div class="tray-sidebar__group">
    <p class="tray-sidebar__label">Workspace</p>
    <a class="tray-sidebar__item" href="/team">…user-plus icon…<span>Team</span></a>
  </div>
  <div class="tray-sidebar__foot">…the account…</div>
</nav>
```

The tray is 17rem wide. Each item is a link in a 44px row: an icon, a label, an optional count. The first group has no label and holds the pages people open every day; a group label is a plain paragraph, not a heading and not a control. Put the most used destinations first, and keep actions such as "New order" out of the sidebar: they are buttons in the page.

The current page is drawn from the same attribute that exposes it to assistive technologies:

```css
.tray-sidebar__item[aria-current] { background: var(--ink); color: var(--tray-on-ink); }
.tray-sidebar__item:focus-visible { outline-offset: -3px; }
```

A class such as `.active` can drift away from the ARIA state; a selector on `[aria-current]` cannot. The focus ring is drawn inside the row, and with forced colours the current item takes the system's colours for a chosen item.

## Marking where the person is

`aria-current` says which item in a set is the current one. MDN lists its values, among them `page`, "the current page within a set of pages", `location`, and `true`, "the current item within a set", and adds: "Only mark one element in a set of elements as current". The blocks use three:

| Where | Value | Block |
| --- | --- | --- |
| The link to the open page, at any level, in a tree too | `page` | All but the calendar and the contents |
| A section button whose menu holds the open page | `true` | [Menus](https://trayui.com/blocks/sidebar-05.md) |
| The current heading of a table of contents | `true` | [At the end](https://trayui.com/blocks/sidebar-11.md) |
| The current sub-heading under it | `location` | [At the end](https://trayui.com/blocks/sidebar-11.md) |

The server writes it into the page. In a single-page app, move it when the route changes. In the table of contents nothing watches the scroll: your script moves both marks as the reader goes down the page.

## Sections that fold

A section that folds is a `<details>` whose `<summary>` is the group label. It needs no script: Enter or Space opens and closes it, and in Chrome's accessibility tree the summary is a disclosure triangle with an expanded state.

```html
<details class="tray-sidebar__group" open>
  <summary class="tray-sidebar__label">Shop <svg class="tray-icon tray-icon--sm" aria-hidden="true">…chevron-right…</svg></summary>
  <a class="tray-sidebar__item" href="/products">…<span>Products</span></a>
  <a class="tray-sidebar__item" href="/delivery">…<span>Delivery</span></a>
</details>
```

```css
summary.tray-sidebar__label { list-style: none; cursor: pointer; }
summary.tray-sidebar__label::-webkit-details-marker { display: none; }
details[open] > summary.tray-sidebar__label > .tray-icon { transform: rotate(90deg); }
```

The first two rules remove the browser's own triangle, and the third turns the chevron a quarter as the section opens. Write `open` on the section that holds the current page, or its marked row is hidden on load. Nothing remembers which sections were open from one page to the next. If that matters, the `toggle` event of `<details>` is where to store it; this script, which is not part of Tray UI, never closes the section that holds the current page:

```js
for (const section of document.querySelectorAll('#nav details')) {
  const key = 'nav:' + section.querySelector('summary').textContent.trim();
  const saved = localStorage.getItem(key);
  if (saved) section.open = saved === 'open' || section.querySelector('[aria-current]') !== null;
  section.addEventListener('toggle', () => localStorage.setItem(key, section.open ? 'open' : 'closed'));
}
```

## A second level

Three blocks put pages under pages, and each shows the second level differently. Keep to two levels: a third belongs in a tree or in the page.

- **Always open.** In [A second level](https://trayui.com/blocks/sidebar-03.md) the parent stays a link to its own page, and a `<ul class="tray-sidebar__sub">` under it holds the sub-pages in 36px rows without icons, stepped in under the label. The current sub-page is white and semibold, so the column keeps one strong mark. The groups sit in `tray-sidebar__scroll`, which scrolls between the wordmark and the account.
- **Folding.** In [A level that folds](https://trayui.com/blocks/sidebar-04.md) the item is the `<summary>` of a `<details class="tray-sidebar__more">`. A summary opens and closes and goes nowhere, so the first entry of the list is the overview, "All orders".
- **A menu beside the item.** In [Menus](https://trayui.com/blocks/sidebar-05.md) the item is the button of a [Dropdown Menu](https://trayui.com/components/dropdown-menu.md) whose panel opens beside the sidebar. Its entries are links with `role="menuitem"`, as in the WAI-ARIA Authoring Practices' [Navigation Menu Button example](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/examples/menu-button-links/). The script gives the button `aria-haspopup="menu"` and `aria-expanded`; Enter or ArrowDown opens the menu on its first page, and Escape closes it and returns focus to the item. `tray-sidebar--flyout` lets the menus out past the tray's edge, so that tray cannot scroll: keep it shorter than the smallest window.

## A rail of icons

[Collapses to icons](https://trayui.com/blocks/sidebar-06.md) adds a button that folds the tray to a rail 76px wide. The labels are hidden from sight only, so every link keeps its name, and each item shows its label in a [Tooltip](https://trayui.com/components/tooltip.md) beside the icon. The Orders link takes its name from its words, with " to pack" hidden after the count, so it is read "Orders 12 to pack" and the bare count means something. The button keeps `aria-expanded` in step and changes its name from "Collapse the sidebar" to "Expand the sidebar", and the sidebar fires `tray:change` as it folds, so you can store the choice. [An admin dashboard in plain HTML and CSS](https://trayui.com/articles/admin-dashboard-html-css.md) has the script and the CSS.

Give every item an icon, since the rail shows nothing else. [Two sidebars](https://trayui.com/blocks/sidebar-08.md) starts its section list as a rail, with `data-collapsed` in the markup and no button to widen it.

## Sidebars that hold something else

Not every side column is the main navigation. Use `<nav>` when it holds links, `<aside>` when it holds tools or details, and name every one: a page with two of them needs the names to tell them apart.

- **[Two sidebars](https://trayui.com/blocks/sidebar-08.md)**: `tray-app__side--double` holds a rail of sections and a 21rem `<nav>` named "Inbox" with the list of messages. An unread message has a dot and the hidden word "Unread".
- **[A file tree](https://trayui.com/blocks/sidebar-09.md)**: a `<nav>` named "Files" with a `tray-tree` of nested lists in 36px rows. Every folder is a `<details>`, and each file a link. A change badge, M, A or D, has `role="img"` and the whole word as its name, such as "Modified".
- **[A calendar](https://trayui.com/blocks/sidebar-10.md)**: an `<aside>` named "Calendars", since nothing in it is a link. The month is a [Calendar](https://trayui.com/components/calendar.md) with one stop for Tab, and each folding group of checkboxes has `role="group"` with a name, such as "My calendars".
- **[At the end](https://trayui.com/blocks/sidebar-11.md)**: `tray-app--end` puts the side after the content. The `<nav>` is named "On this page" and lists the headings of this page.
- **[On each side](https://trayui.com/blocks/sidebar-12.md)**: `tray-app--both` adds an `<aside>` at the end named "Details of order PL-20431". With `tray-app__side--late` it waits until the window is 80rem wide.
- **[Inset](https://trayui.com/blocks/sidebar-07.md)** and **[Under a site header](https://trayui.com/blocks/sidebar-13.md)**: `tray-app--inset` makes the whole window a tray with the page as one white panel; `tray-app--header` puts one sticky header over both columns.
- **[In a dialog](https://trayui.com/blocks/sidebar-14.md)**: a second `<nav>`, "Sections of the settings", inside a modal [Dialog](https://trayui.com/components/dialog.md) named "Settings". Below 48rem it turns into one row that scrolls sideways.
- **[In a popover](https://trayui.com/blocks/sidebar-15.md)**: no shell at all. A Menu button opens a [Popover](https://trayui.com/components/popover.md) holding a `tray-sidebar--plain`, which has no tray of its own. Focus moves to the first link, and Escape returns it to the button.

## On a phone

Below 56rem, every sidebar of the shell leaves the page. A menu button in the top bar moves that same `<nav>` into a modal `<dialog>`, and puts it back when the dialog closes. Moving the element keeps one copy of the links to write and to mark with `aria-current`. A version of your own:

```js
const menu = document.getElementById('menu'); // aria-controls="nav" aria-haspopup="dialog" aria-expanded="false"
const nav = document.getElementById(menu.getAttribute('aria-controls'));
const home = nav.parentElement;
const sheet = document.createElement('dialog');
sheet.setAttribute('aria-label', nav.getAttribute('aria-label'));
document.body.append(sheet);

menu.addEventListener('click', () => {
  sheet.append(nav);
  sheet.showModal();
  menu.setAttribute('aria-expanded', 'true');
});
sheet.addEventListener('close', () => {
  home.append(nav);
  menu.setAttribute('aria-expanded', 'false');
});
sheet.addEventListener('click', (event) => {
  if (event.target.closest('a[href]')) sheet.close();
});
```

`showModal()` moves focus into the dialog, Escape closes it, and in Chromium focus returns to the menu button without a line of script. Following a link closes the sheet too.

In Tray UI the button is `data-tray="sidebar-sheet"` with `aria-controls`. The sheet comes from the side the sidebar is on: from the end for the contents of [At the end](https://trayui.com/blocks/sidebar-11.md) and the details of [On each side](https://trayui.com/blocks/sidebar-12.md). It takes the sidebar's name, so the file tree's sheet is "Files". A rail shows its labels in the sheet and folds back into a rail when the sheet closes. A page with two sidebars has two buttons, one for each, so nothing is out of reach on a phone.

## Sidebars in Tray UI

The [Sidebar](https://trayui.com/components/sidebar.md) page has the parts and the rules for writing items, and [App Shell](https://trayui.com/components/app-shell.md) the frame around them. [Page layouts](https://trayui.com/docs/layouts.md) lists every variant of both: the inset page, the header across the product, the sidebar at the end or on each side. Each block on [Sidebars](https://trayui.com/blocks/sidebar.md) can be opened at desktop, tablet and phone width and copied whole; it needs the three files from [Installation](https://trayui.com/docs/installation.md), and its folding parts work before any script runs.
