Site sidebar
The side menu of a docs site, a help center or a blog: groups of links next to the content, with an optional "On this page" list on the other side that follows along as you read. On a narrow screen the sidebar tucks away behind a Menu button and slides in from the side.
Sidebar
The sidebar sticks below the navbar while the content scrolls. Folding groups are <details>; the group holding the current page (aria-current="page") opens by itself.
Sections
The page content goes here. When this box is narrower than 832px, the sidebar becomes a panel behind the Menu button; try it on a phone or make the window narrow.
<div class="site-layout">
<aside class="site-sidebar" aria-label="Docs">
<div class="site-sidebar-head"><b>Docs</b><button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button></div>
<nav class="site-nav" aria-label="Docs pages">
<div class="site-nav-group">
<p class="site-nav-title">Get started</p>
<ul>
<li><a href="#"><i class="mi mi-rocket" aria-hidden="true"></i>Introduction</a></li>
<li><a href="#"><i class="mi mi-download" aria-hidden="true"></i>Install</a></li>
<li><a href="#"><i class="mi mi-palette" aria-hidden="true"></i>Customize <span class="badge badge-green">New</span></a></li>
</ul>
</div>
<div class="site-nav-group">
<p class="site-nav-title">Guides</p>
<ul>
<li>
<details>
<summary>Landing pages<i class="mi mi-chevron-right site-nav-caret rtl-flip" aria-hidden="true"></i></summary>
<ul><li><a href="#">The hero</a></li><li><a href="#" aria-current="page">Sections</a></li><li><a href="#">The footer</a></li></ul>
</details>
</li>
<li>
<details>
<summary>Docs sites<i class="mi mi-chevron-right site-nav-caret rtl-flip" aria-hidden="true"></i></summary>
<ul><li><a href="#">The sidebar</a></li><li><a href="#">Search</a></li></ul>
</details>
</li>
<li><a href="#">Dark mode</a></li>
</ul>
</div>
</nav>
</aside>
<main class="site-main">
<button class="btn btn-sm site-sidebar-toggle" type="button"><i class="mi mi-panel-left" aria-hidden="true"></i> Menu</button>
<span class="eyebrow">Landing pages</span>
<h3 class="mt-1">Sections</h3>
<p class="text-muted">The page content goes here. When this box is narrower than 832px, the sidebar becomes a panel behind the Menu button; try it on a phone or make the window narrow.</p>
</main>
</div>On a phone
The same markup in a narrow box. Press Menu: the sidebar slides in from the side; a tap outside, Esc or picking a page closes it.
Introduction
Page content…
<div class="max-w-sm mx-auto box p-5">
<div class="site-layout">
<aside class="site-sidebar" aria-label="Docs (phone)">
<div class="site-sidebar-head"><b>Docs</b><button class="btn btn-icon btn-sm btn-ghost" type="button" data-momo-close aria-label="Close"><i class="mi mi-x" aria-hidden="true"></i></button></div>
<nav class="site-nav" aria-label="Docs pages (phone)">
<div class="site-nav-group">
<p class="site-nav-title">Get started</p>
<ul>
<li><a href="#" aria-current="page"><i class="mi mi-rocket" aria-hidden="true"></i>Introduction</a></li>
<li><a href="#"><i class="mi mi-download" aria-hidden="true"></i>Install</a></li>
<li><a href="#"><i class="mi mi-palette" aria-hidden="true"></i>Customize</a></li>
</ul>
</div>
</nav>
</aside>
<main class="site-main">
<button class="btn btn-sm site-sidebar-toggle" type="button"><i class="mi mi-panel-left" aria-hidden="true"></i> Menu</button>
<h3 class="m-0">Introduction</h3>
<p class="text-muted mb-0">Page content…</p>
</main>
</div>
</div>On this page
Add a .site-toc after .site-main: a list of links to the headings on the page. Momo marks the section you are reading as you scroll (it gets .is-active and aria-current="location"). It shows when the layout is at least 1088px wide, so see it on the example page.
<aside class="site-toc" aria-label="On this page">
<p class="site-toc-title">On this page</p>
<ul>
<li><a href="#install">Install</a></li>
<li><a href="#usage">Usage</a>
<ul><li><a href="#options">Options</a></li></ul>
</li>
</ul>
</aside>
The same follow-along marking works on any menu of #section links: give it data-momo-scrollspy.
The whole layout
<div class="site-layout container container-xl">
<aside class="site-sidebar" aria-label="Docs">
<div class="site-sidebar-head">…title and a data-momo-close button…</div>
<nav class="site-nav">
<div class="site-nav-group">
<p class="site-nav-title">Get started</p>
<ul><li><a href="…" aria-current="page">Install</a></li></ul>
</div>
</nav>
</aside>
<main class="site-main">
<button class="btn btn-sm site-sidebar-toggle" type="button">Menu</button>
…
</main>
<aside class="site-toc" aria-label="On this page">…</aside>
</div>
Classes
| Class | Does |
|---|---|
.site-layout | Sidebar, content and "On this page" side by side. It measures its own width: the sidebar shows from 832px, the list from 1088px. |
.site-sidebar | The sidebar, 240px (--site-sidebar-w), sticky below a sticky navbar |
.site-sidebar-toggle | The button that opens it when narrow (hidden when wide) |
.site-sidebar-head | Title and close button, shown only in the narrow panel |
.site-nav / -group / -title / -caret | The menu: groups with a small heading, links with icons and badges, <details> for folding |
.site-main | The content |
.site-toc / .site-toc-title | "On this page", 208px (--site-toc-w), follows along as you read |
data-momo-scrollspy | Follow-along marking for any menu of #section links |
Without JavaScript a narrow sidebar sits above the content instead of hiding.
Accessibility
- Give each
<aside>a name (aria-label="Docs","On this page") so screen readers can tell them apart. - Mark the current page with
aria-current="page"; it is read out and highlighted. - The Menu button says whether the panel is open; the panel takes focus on the current page's link and gives it back when it closes.