App sidebar
A sidebar with grouped navigation, counts and the signed-in user; it becomes an off-canvas drawer below 992px.
- Version 1.1.0
- Bootstrap 5.3+
- Requires Bootstrap CSS + Bootstrap JS bundle
- Source on GitHub
html
<button
class="btn bootcn-button bootcn-button--outline bootcn-button--sm d-lg-none bootcn-sidebar__open"
type="button"
data-bs-toggle="offcanvas"
data-bs-target="#bootcn-sidebar"
aria-controls="bootcn-sidebar"
>
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M4 6h16M4 12h16M4 18h16" />
</svg>
Menu
</button>
<aside
class="offcanvas-lg offcanvas-start bootcn-sidebar"
tabindex="-1"
id="bootcn-sidebar"
aria-label="Sidebar"
>
<div class="offcanvas-header bootcn-sidebar__header">
<p class="offcanvas-title bootcn-sidebar__brand">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<rect x="3" y="3" width="8" height="8" rx="2" />
<rect x="13" y="13" width="8" height="8" rx="2" />
<path d="M13 7h8M17 3v8M3 17h8" />
</svg>
Acme
</p>
<button
type="button"
class="btn-close"
data-bs-dismiss="offcanvas"
data-bs-target="#bootcn-sidebar"
aria-label="Close menu"
></button>
</div>
<div class="offcanvas-body bootcn-sidebar__body">
<a class="bootcn-sidebar__brand d-none d-lg-flex" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<rect x="3" y="3" width="8" height="8" rx="2" />
<rect x="13" y="13" width="8" height="8" rx="2" />
<path d="M13 7h8M17 3v8M3 17h8" />
</svg>
Acme
</a>
<nav class="bootcn-sidebar__nav" aria-label="Main">
<p class="bootcn-sidebar__heading" id="bootcn-sidebar-workspace">Workspace</p>
<ul class="bootcn-sidebar__list" aria-labelledby="bootcn-sidebar-workspace">
<li>
<a class="bootcn-sidebar__link" href="#" aria-current="page">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M3 11l9-8 9 8" />
<path d="M5 10v10h14V10" />
</svg>
<span>Dashboard</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M3 6h6l2 2h10v11H3z" />
</svg>
<span>Projects</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M3 13h5l2 3h4l2-3h5" />
<path d="M5 5h14l2 8v6H3v-6z" />
</svg>
<span>Inbox</span>
<span class="badge bootcn-badge bootcn-badge--secondary bootcn-sidebar__count"
>4<span class="visually-hidden"> unread</span></span
>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M4 20V10" />
<path d="M10 20V4" />
<path d="M16 20v-7" />
<path d="M2 20h20" />
</svg>
<span>Reports</span>
</a>
</li>
</ul>
<p class="bootcn-sidebar__heading" id="bootcn-sidebar-account">Account</p>
<ul class="bootcn-sidebar__list" aria-labelledby="bootcn-sidebar-account">
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="9" cy="8" r="4" />
<path d="M2 21c0-4 3-7 7-7s7 3 7 7" />
<path d="M17 4a4 4 0 0 1 0 8" />
<path d="M22 21c0-3-2-6-5-7" />
</svg>
<span>Team</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M4 6h9" />
<path d="M19 6h1" />
<circle cx="16" cy="6" r="2" />
<path d="M4 18h3" />
<path d="M13 18h7" />
<circle cx="10" cy="18" r="2" />
<path d="M4 12h1" />
<path d="M11 12h9" />
<circle cx="8" cy="12" r="2" />
</svg>
<span>Settings</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="12" cy="12" r="9" />
<path d="M9.5 9a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.7" />
<path d="M12 17h.01" />
</svg>
<span>Help</span>
</a>
</li>
</ul>
</nav>
<div class="bootcn-sidebar__user">
<span class="bootcn-avatar bootcn-avatar--sm" aria-hidden="true"
><span class="bootcn-avatar__fallback">MP</span></span
>
<div class="bootcn-sidebar__user-text">
<span class="bootcn-sidebar__user-name">Maria Papadopoulou</span>
<span class="bootcn-sidebar__user-email">maria@example.com</span>
</div>
</div>
</div>
</aside>Installation
bash
npx bootcn add app-sidebarbash
pnpm dlx bootcn add app-sidebarbash
yarn dlx bootcn add app-sidebarbash
bunx --bun bootcn add app-sidebarThe CLI also installs the design tokens and these blocks and components: button, badge, avatar. It prints the <link> and <script> tags to add to your layout.
- Load Bootstrap 5.3 (Bootstrap CSS + Bootstrap JS bundle) and the design tokens.
- Install the blocks and components it uses:
button,badge,avatar. - Copy the files from Source into your project. With the default
bootcn.jsonthey go here:
| File | Default location |
|---|---|
app-sidebar.html | components/ui/app-sidebar.html |
app-sidebar.css | assets/css/app-sidebar.css |
Usage
Place the sidebar and your main content side by side, for example:
html
<div class="d-lg-flex min-vh-100">
<!-- sidebar markup -->
<main class="flex-grow-1 p-4">…</main>
</div>Below 992px the sidebar is a Bootstrap off-canvas drawer opened by the "Menu" button; move that button into your top bar (a <header>), so it sits inside a landmark. Mark the current page with aria-current="page". The drawer needs the Bootstrap JS bundle.
Accessibility
- The sidebar is an
<aside aria-label="Sidebar">landmark with a<nav aria-label="Main">inside; each group of links is a list labelled by its heading. - Unread counts carry visually hidden text ("4 unread").
- As a drawer, Bootstrap moves focus into it, traps it while open, and closes it on Escape; focus returns to the "Menu" button.
Dependencies
- Bootstrap 5.3+ CSS and the JS bundle.
themes/tokens/tokens.css.- The
buttoncomponent. - The
badgecomponent. - The
avatarcomponent.
Source
The exact files the CLI installs (app-sidebar@1.1.0). View on GitHub · Report an issue
html
<button
class="btn bootcn-button bootcn-button--outline bootcn-button--sm d-lg-none bootcn-sidebar__open"
type="button"
data-bs-toggle="offcanvas"
data-bs-target="#bootcn-sidebar"
aria-controls="bootcn-sidebar"
>
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M4 6h16M4 12h16M4 18h16" />
</svg>
Menu
</button>
<aside
class="offcanvas-lg offcanvas-start bootcn-sidebar"
tabindex="-1"
id="bootcn-sidebar"
aria-label="Sidebar"
>
<div class="offcanvas-header bootcn-sidebar__header">
<p class="offcanvas-title bootcn-sidebar__brand">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<rect x="3" y="3" width="8" height="8" rx="2" />
<rect x="13" y="13" width="8" height="8" rx="2" />
<path d="M13 7h8M17 3v8M3 17h8" />
</svg>
Acme
</p>
<button
type="button"
class="btn-close"
data-bs-dismiss="offcanvas"
data-bs-target="#bootcn-sidebar"
aria-label="Close menu"
></button>
</div>
<div class="offcanvas-body bootcn-sidebar__body">
<a class="bootcn-sidebar__brand d-none d-lg-flex" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<rect x="3" y="3" width="8" height="8" rx="2" />
<rect x="13" y="13" width="8" height="8" rx="2" />
<path d="M13 7h8M17 3v8M3 17h8" />
</svg>
Acme
</a>
<nav class="bootcn-sidebar__nav" aria-label="Main">
<p class="bootcn-sidebar__heading" id="bootcn-sidebar-workspace">Workspace</p>
<ul class="bootcn-sidebar__list" aria-labelledby="bootcn-sidebar-workspace">
<li>
<a class="bootcn-sidebar__link" href="#" aria-current="page">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M3 11l9-8 9 8" />
<path d="M5 10v10h14V10" />
</svg>
<span>Dashboard</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M3 6h6l2 2h10v11H3z" />
</svg>
<span>Projects</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M3 13h5l2 3h4l2-3h5" />
<path d="M5 5h14l2 8v6H3v-6z" />
</svg>
<span>Inbox</span>
<span class="badge bootcn-badge bootcn-badge--secondary bootcn-sidebar__count"
>4<span class="visually-hidden"> unread</span></span
>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M4 20V10" />
<path d="M10 20V4" />
<path d="M16 20v-7" />
<path d="M2 20h20" />
</svg>
<span>Reports</span>
</a>
</li>
</ul>
<p class="bootcn-sidebar__heading" id="bootcn-sidebar-account">Account</p>
<ul class="bootcn-sidebar__list" aria-labelledby="bootcn-sidebar-account">
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="9" cy="8" r="4" />
<path d="M2 21c0-4 3-7 7-7s7 3 7 7" />
<path d="M17 4a4 4 0 0 1 0 8" />
<path d="M22 21c0-3-2-6-5-7" />
</svg>
<span>Team</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M4 6h9" />
<path d="M19 6h1" />
<circle cx="16" cy="6" r="2" />
<path d="M4 18h3" />
<path d="M13 18h7" />
<circle cx="10" cy="18" r="2" />
<path d="M4 12h1" />
<path d="M11 12h9" />
<circle cx="8" cy="12" r="2" />
</svg>
<span>Settings</span>
</a>
</li>
<li>
<a class="bootcn-sidebar__link" href="#">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="12" cy="12" r="9" />
<path d="M9.5 9a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.7" />
<path d="M12 17h.01" />
</svg>
<span>Help</span>
</a>
</li>
</ul>
</nav>
<div class="bootcn-sidebar__user">
<span class="bootcn-avatar bootcn-avatar--sm" aria-hidden="true"
><span class="bootcn-avatar__fallback">MP</span></span
>
<div class="bootcn-sidebar__user-text">
<span class="bootcn-sidebar__user-name">Maria Papadopoulou</span>
<span class="bootcn-sidebar__user-email">maria@example.com</span>
</div>
</div>
</div>
</aside>css
/* A static column from 992px (Bootstrap's offcanvas-lg); an off-canvas
drawer below it. Set the width with --bootcn-sidebar-width. */
.bootcn-sidebar {
--bootcn-sidebar-width: 16rem;
--bs-offcanvas-width: var(--bootcn-sidebar-width);
--bs-offcanvas-bg: var(--bs-body-bg);
}
.bootcn-sidebar__open {
gap: 0.375rem;
}
@media (min-width: 992px) {
.bootcn-sidebar {
flex: 0 0 var(--bootcn-sidebar-width);
width: var(--bootcn-sidebar-width);
border-right: var(--bootcn-border-width) solid var(--bootcn-border-color);
background-color: var(--bs-tertiary-bg);
}
}
.bootcn-sidebar__body {
display: flex;
flex-direction: column;
gap: 1rem;
height: 100%;
padding: 1rem 0.75rem;
}
.bootcn-sidebar__brand {
display: flex;
align-items: center;
gap: 0.5rem;
margin: 0;
padding: 0.25rem 0.5rem;
color: var(--bs-emphasis-color);
font-weight: 600;
font-size: 1.0625rem;
text-decoration: none;
}
.bootcn-sidebar__brand .bootcn-icon {
width: 1.25rem;
height: 1.25rem;
}
.bootcn-sidebar__nav {
flex: 1 1 auto;
}
.bootcn-sidebar__heading {
margin: 0.75rem 0 0.25rem;
padding: 0 0.5rem;
color: var(--bs-secondary-color);
font-size: 0.75rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.bootcn-sidebar__list {
margin: 0;
padding: 0;
list-style: none;
}
.bootcn-sidebar__link {
display: flex;
align-items: center;
gap: 0.625rem;
padding: 0.5rem;
border-radius: var(--bootcn-radius);
color: var(--bs-body-color);
font-size: 0.875rem;
font-weight: 500;
text-decoration: none;
}
.bootcn-sidebar__link .bootcn-icon {
flex: none;
color: var(--bs-secondary-color);
}
.bootcn-sidebar__link:hover {
background-color: var(--bootcn-accent);
color: var(--bs-emphasis-color);
}
.bootcn-sidebar__link[aria-current='page'] {
background-color: var(--bs-secondary-bg);
color: var(--bs-emphasis-color);
}
.bootcn-sidebar__link[aria-current='page'] .bootcn-icon {
color: var(--bs-emphasis-color);
}
.bootcn-sidebar__link:focus-visible {
outline: 0;
box-shadow: var(--bootcn-focus-ring);
}
.bootcn-sidebar__count {
margin-left: auto;
}
.bootcn-sidebar__user {
display: flex;
align-items: center;
gap: 0.625rem;
padding: 0.75rem 0.5rem 0;
border-top: var(--bootcn-border-width) solid var(--bootcn-border-color);
}
.bootcn-sidebar__user-text {
display: flex;
flex-direction: column;
min-width: 0;
}
.bootcn-sidebar__user-name {
color: var(--bs-emphasis-color);
font-size: 0.875rem;
font-weight: 600;
}
.bootcn-sidebar__user-email {
overflow: hidden;
color: var(--bs-secondary-color);
font-size: 0.8125rem;
text-overflow: ellipsis;
white-space: nowrap;
}
