Sidebar
Use data-sidebar-layout on a container (typically <body>) with <aside data-sidebar> for the sidebar and <main> for content. The sidebar stays sticky while the main content scrolls. On mobile, the sidebar becomes a slide-out overlay toggled by a [data-sidebar-toggle] button. To make the sidebar collapsible at all widths, set data-sidebar-layout="always".
Always-collapsible
Set data-sidebar-layout="always" to keep the toggle visible on all screen sizes.
<body data-sidebar-layout="always">
...
</body>With top sticky nav
Add data-topnav to a header element for a full-width top navigation bar. The sidebar will adjust to sit below it. Inspect the HTML source of this website for a live example.
<body data-sidebar-layout>
<nav data-topnav>
<button data-sidebar-toggle aria-label="Toggle menu" class="outline">☰</button>
<span>App Name</span>
</nav>
<aside data-sidebar>
<header>Logo</header>
<nav>...navigation...</nav>
<footer>Actions</footer>
</aside>
<main>
Main page content.
</main>
</body>Structure
| Attribute | Element | |
|---|---|---|
data-sidebar-layout | Container | Grid layout wrapper (sidebar + main), typically <body> |
data-sidebar-layout="always" | Container | Always-collapsible sidebar (toggle visible on screen sizes) |
data-topnav | <header> | Full-width top nav (optional, spans full width) |
data-sidebar | <aside> | Sticky sidebar element |
data-sidebar-toggle | <button> | Toggles sidebar (mobile) and collapse (always mode) |
data-sidebar-open | Layout | Applied to layout when sidebar is open |