Sidebar
- Use
data-sidebar-layouton 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 show the toggle and make it collapse the sidebar at all widths, setdata-sidebar-layout="always". - Set the
--sidebar-widthvariable to adjust its width globally.
Always-collapsible
Set data-sidebar-layout="always" to keep the toggle visible and make it collapse the sidebar on all screen sizes.
<body data-sidebar-layout="always">
...
</body>With top sticky nav
Add data-topnav to a nav 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 and functional on all screen sizes) |
data-topnav | <nav> | 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 |