App shell
Status: shipped in domestic-ui as a layout (data-app-shell) plus one web component (<dui-app-shell>).
CSS: css/layout/app-shell.css ·
Script: web-components/dui-app-shell.js ·
Examples: examples/app-shell.html (a full orders screen),
examples/layouts/app-shell.html (a contained shell)
The key words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are to be interpreted as described in RFC 2119 and RFC 8174 when, and only when, they appear in all capitals.
Problem
Business applications share one frame: an app bar across the top, navigation down one side, the work in
the middle, and often a second sidebar with the context of what is selected. HTML has the landmarks for
every part (<header>, <nav>, <main>, <aside>, <footer>) and the
APG Landmark Regions practice says how to
label them, but no standard says how they become an app frame that collapses its sidebars and turns them
into drawers on a phone. Common implementations:
- render the navigation twice (a sidebar and a mobile menu), so screen reader users meet two navigation landmarks and the markup drifts apart;
- keep the sidebar in a
role="dialog"at every width, so the permanent sidebar of a desktop page is announced as a dialog; - switch on the viewport width, so a shell inside a docs page or a resizable panel picks the wrong mode;
- hide the sidebar with a CSS checkbox hack or
transform, leaving it in the Tab order or with noaria-expandedon its button; - show a "Menu" button that does nothing before (or without) JavaScript.
Use cases
- An operations screen: orders in a table, the main navigation on the left, the selected order on the right.
- A settings area: navigation groups beside a long form.
- The same application on a phone: navigation and details open as drawers from their edges.
- A shell embedded in a page section (a documentation example, a preview pane), sized by its box.
Goals
- Native landmarks in source order, which is also the reading and Tab order at every width (2.4.3 Focus Order).
- One copy of each sidebar in the DOM, in every mode.
- Everything visible and usable with JavaScript off: no dead buttons, the current page marked.
- Wide: each sidebar collapses and expands with a disclosure button. Main takes the space.
- Narrow: each sidebar opens as a modal drawer with everything a modal dialog does.
- The mode follows the shell's own width, so a contained shell works anywhere.
- Layouts and organisms inside main respond to the width main has.
- No horizontal scrolling at 320px (1.4.10 Reflow); motion from the tokens, off under reduced motion (2.3.3).
Non-goals
- Resizable sidebars (see Open questions).
- A sidebar shrunk to a rail of icons. A rail needs tooltips or visible names for every icon and a second layout of the same links. Collapsing to hidden is simpler and fully accessible.
- Persisting the collapsed state across visits (an event makes it possible; storage is the page's job).
- Routing: links in the navigation load pages. A single-page app may intercept them.
Proposed markup and API
- The shell MUST be one element with
data-app-shell:<dui-app-shell data-app-shell>to get the toggles' behavior, or any wrapper element for a static shell. - A skip link to
<main>MUST come before the shell, as its own first focusable element (2.4.1 Bypass Blocks). - Its children, in this order: a
<header>(the app bar); the primary sidebar;<main>; an optional auxiliary<aside>; an optional<footer>. Parts are recognized by element and position, so they need no attributes: the<nav>or<aside>before<main>is the primary sidebar, the<aside>after it the auxiliary one. - The primary sidebar SHOULD be a
<nav aria-label>(usually withdata-nav="vertical"). It MAY be an<aside aria-label>holding the primary<nav>when it also holds things that are not links (a workspace switcher). It MUST NOT be a<div>: it would not be a landmark. - Every
<nav>and<aside>MUST have an accessible name that does not repeat its role ("Main", "Order details"). Two landmarks of the same kind MUST have different names. - A sidebar with a toggle MUST have an
id. Its toggle is a<button type="button" aria-controls="id" aria-expanded="true" hidden>; it MUST carryhiddenin the markup, so it never shows without the script.aria-expanded="false"in the markup starts the sidebar collapsed when it sits beside main (an aux sidebar on a busy screen). At least one toggle MUST be outside the sidebar. data-app-shell="contained"makes the shell--dui-size-panetall with its own scroll area. Set--dui-size-paneon it to size it.- Tokens:
--dui-size-sidebar(16rem) and--dui-size-sidebar-aux(20rem) are the sidebar widths beside main.--dui-size-panebounds a sidebar's height beside main.
<a class="visually-hidden" href="#main">Skip to main content</a>
<dui-app-shell data-app-shell>
<header>
<button type="button" aria-controls="app-nav" aria-expanded="true" hidden>Menu</button>
<a href="/">Northwind Operations</a>
<button type="button" aria-controls="app-aux" aria-expanded="true" hidden>Details</button>
</header>
<nav id="app-nav" aria-label="Main" data-nav="vertical">…</nav>
<main id="main">…</main>
<aside id="app-aux" aria-label="Order details">…</aside>
</dui-app-shell>
<script type="module" src="web-components/dui-app-shell.js"></script>
Modes
| Shell width | Primary sidebar | Auxiliary sidebar | Without JavaScript |
|---|---|---|---|
| under 48rem | drawer at the start | drawer at the end | both stacked, above and below main |
| 48rem to 64rem | beside main, collapsible | drawer at the end | aux stacked under main |
| 64rem and up | beside main, collapsible | beside main, collapsible | both beside main |
The breakpoints are lengths in @container dui-app-shell rules (a container query cannot read a custom
property), and the same two numbers are in the script.
- In a drawer the sidebar element is moved into a
<dialog data-dialog="drawer start | end" closedby="any">(drawer explainer) that the element builds once, with a heading (the toggle's text) and a Close button, opened withshowModal(). When it closes, the sidebar is moved back to where it was. <main>and each sidebar are named size containers (dui-app-shell-main,dui-app-shell-start,dui-app-shell-end). Every layout and organism in domestic-ui switches on its own box, so they adapt to main's width. A page MAY write its own@container dui-app-shell-mainrules.- Methods
show(edge),hide(edge),toggle(edge)andisDrawer(edge)("start"or"end") let a page open the details when a record is chosen. Adui-app-shell-toggleevent reports every change.
Our choice: one copy of each sidebar, a plain landmark in its grid area, moved into a drawer only while the drawer is open, so screen readers never hear "dialog" around a sidebar that is part of the page.
Our choice: the mode follows the shell's width (a ResizeObserver and container queries), not the
viewport, so a contained shell behaves like a full-window one.
Keyboard interaction
- Tab / Shift+Tab: the skip link, the app bar, the primary sidebar, main, the auxiliary sidebar, the
footer, in source order. A collapsed sidebar is
hidden, so it is skipped. - Enter / Space on a toggle (native button): collapses or expands its sidebar. On a narrow shell, opens it as a drawer and moves focus to the drawer's first focusable element (its Close button).
- Esc in a drawer: closes it. Focus returns to the element that opened it (the toggle, or a link that
called
show()), and the toggle'saria-expandedbecomesfalse. - A click on the backdrop closes a drawer (
closedby="any", with a script fallback where it is not supported). - Enter / Space on a group summary in the navigation: opens or closes the group (native
<details>).
Accessibility mappings
| Element | Role | Name / state |
|---|---|---|
<header> (not inside a sectioning element) | banner (HTML-AAM) | |
<nav aria-label="Main"> | navigation | "Main" |
<main> | main | |
<aside aria-label="Order details"> | complementary (HTML-AAM) | "Order details" |
<footer> | contentinfo | |
| Toggle | button | its text; aria-expanded true while shown or open; aria-controls the sidebar |
| Collapsed sidebar | none (hidden) | removed from the accessibility tree and the Tab order |
| Drawer | dialog, modal | its heading (the toggle's text); the rest of the page is inert |
What a screen reader user hears, for example: on a wide screen, "Menu, button, expanded", and in the landmarks list "banner, Main navigation, main, Order details complementary, content information". On a phone, "Menu, button, collapsed". After Enter, "Menu, dialog, Close, button", then the "Main" navigation inside it. After Esc, focus is back on "Menu, button, collapsed".
Alternatives considered
- (a) The sidebar always lives in a
<dialog>, opened withshow()(non-modal, placed in the grid) when wide andshowModal()when narrow. One copy, no DOM moves. Rejected: the permanent sidebar of a desktop page is announced as a dialog, a non-modal<dialog>is not a landmark, and with JavaScript off a closed dialog hides the navigation (anopenattribute in the markup works around that but is discouraged by HTML). - (b) The sidebar is a plain landmark, moved into a drawer
<dialog>while narrow. Chosen, with one refinement: it is moved only while the drawer is open, not for the whole narrow mode, so between opens it sits hidden in its own place and a mode change never moves it. - (c) A
popoverinstead of a dialog for the narrow mode. A popover can be the sidebar itself (no move) and light-dismisses, but it is not modal: the page behind stays in the Tab order and the accessibility tree, which a full-height navigation drawer covering the page should not allow. Rejected for the drawer. It remains a candidate for a non-modal side panel (see the drawer explainer). <details>for collapse. Works without script, but the summary must sit inside the sidebar, so the toggle cannot live in the app bar; the content cannot be a drawer; and a closed<details>cannot be shown again at a wider width without script. Rejected.- CSS-only checkbox hacks (
:checked ~ nav). The checkbox is announced as a checkbox, not a button with an expanded state, it stays in the Tab order with nothing to toggle when CSS lays everything out, and the drawer has no modality or Esc. Rejected. - Duplicated navigation (a sidebar and a separate mobile menu). Two navigation landmarks with the same links, two places to mark the current page, and twice the markup for server rendering. Rejected.
- Viewport media queries for the mode. Break a shell inside a page section or a resizable pane.
Rejected in favor of container queries and a
ResizeObserveron the shell.
Prior art
- APG Landmark Regions and the APG Disclosure pattern (the toggles).
- APG Dialog (Modal) and the WHATWG
<main>and<aside>elements. - MDN
grid-template-areas, container queries andResizeObserver. - Design systems: Apple HIG Sidebars, Carbon UI shell header, Primer PageLayout, Atlassian Page layout, GOV.UK Service navigation.
- Open UI has no app shell or sidebar proposal. This explainer is written so the parts could map onto native landmarks unchanged.
Mapping to a future standard
None known. The contract is "landmarks in named grid areas, with sidebars that collapse beside main and become a
modal drawer when the shell is narrow". The layout half is already standard CSS (grid template
areas and container
queries). If HTML gained a way to
present an element modally in place (rather than moving it into a <dialog>), <dui-app-shell> would keep only
the toggle state, and that could move to invoker commands
once a command can toggle hidden.
Open questions
- Resizable sidebars. A draggable edge would follow the
APG Window Splitter pattern (a focusable
role="separator"witharia-valuenowand arrow keys), as noted for the split view. Not built until a real use needs it. - Persisting the collapsed state. The
dui-app-shell-toggleevent carriesexpanded. A page MAY store it (a cookie the server reads, so the markup can start witharia-expanded="false", avoids a flash;localStorageworks too). Should the element do this itself? - A flash on narrow screens. With JavaScript on, the stacked sidebars show until the module runs. A
server that knows the client is narrow can render the sidebars
hiddenand the toggles visible. Should the element offer a hook for that? - Rails. Is there a version of an icon rail that keeps names visible and needs no duplicate links?