App navbar
A responsive top navigation bar with brand, links, search and a user menu that collapses on small screens.
- Version 1.1.0
- Bootstrap 5.3+
- Requires Bootstrap CSS + Bootstrap JS bundle
- Source on GitHub
html
<nav class="navbar navbar-expand-lg bootcn-navbar" aria-label="Main">
<div class="container-fluid">
<a class="navbar-brand bootcn-navbar__brand" 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>
<button
class="navbar-toggler bootcn-navbar__toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#bootcn-navbar-menu"
aria-controls="bootcn-navbar-menu"
aria-expanded="false"
aria-label="Toggle navigation"
>
<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>
</button>
<div class="collapse navbar-collapse" id="bootcn-navbar-menu">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link bootcn-navbar__link active" aria-current="page" href="#">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-navbar__link" href="#">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-navbar__link" href="#">Team</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-navbar__link" href="#">Reports</a>
</li>
</ul>
<form class="bootcn-navbar__search" role="search" aria-label="Site" action="#">
<label class="visually-hidden" for="bootcn-navbar-search">Search</label>
<input
class="form-control bootcn-input"
type="search"
id="bootcn-navbar-search"
name="q"
placeholder="Search…"
/>
<button type="submit" class="visually-hidden">Search</button>
</form>
<div class="dropdown bootcn-dropdown bootcn-user-menu">
<button
class="btn bootcn-user-menu__trigger"
type="button"
id="bootcn-navbar-user-trigger"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<span class="bootcn-avatar bootcn-avatar--sm" aria-hidden="true"
><span class="bootcn-avatar__fallback">MP</span></span
>
<span class="bootcn-user-menu__name">Maria Papadopoulou</span>
<svg
class="bootcn-user-menu__chevron"
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="M6 9l6 6 6-6" />
</svg>
</button>
<ul
class="dropdown-menu dropdown-menu-end bootcn-dropdown__menu"
aria-labelledby="bootcn-navbar-user-trigger"
>
<li>
<p class="dropdown-header bootcn-user-menu__header">
<span class="bootcn-user-menu__header-name">Maria Papadopoulou</span>
<span class="bootcn-user-menu__email">maria@example.com</span>
</p>
</li>
<li><hr class="dropdown-divider bootcn-dropdown__divider" /></li>
<li><a class="dropdown-item bootcn-dropdown__item" href="#profile">Profile</a></li>
<li><a class="dropdown-item bootcn-dropdown__item" href="#billing">Billing</a></li>
<li><a class="dropdown-item bootcn-dropdown__item" href="#settings">Settings</a></li>
<li><hr class="dropdown-divider bootcn-dropdown__divider" /></li>
<li>
<button
class="dropdown-item bootcn-dropdown__item bootcn-dropdown__item--destructive"
type="button"
>
Sign out
</button>
</li>
</ul>
</div>
</div>
</div>
</nav>Installation
bash
npx bootcn add app-navbarbash
pnpm dlx bootcn add app-navbarbash
yarn dlx bootcn add app-navbarbash
bunx --bun bootcn add app-navbarThe CLI also installs the design tokens and these blocks and components: user-menu, input. 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:
user-menu,input. - Copy the files from Source into your project. With the default
bootcn.jsonthey go here:
| File | Default location |
|---|---|
app-navbar.html | components/ui/app-navbar.html |
app-navbar.css | assets/css/app-navbar.css |
Usage
Use it as the first element of <body> (wrap it in <header> if you like). Mark the current page's link with active and aria-current="page".
Below 992px the links, search and user menu collapse behind the menu button. Collapse and the user menu need the Bootstrap JS bundle.
Accessibility
<nav aria-label="Main">makes it a named navigation landmark.- The menu button has an accessible name and Bootstrap keeps
aria-expandedin sync. - The current page is announced via
aria-current="page", not only by styling.
Dependencies
- Bootstrap 5.3+ CSS and the JS bundle.
themes/tokens/tokens.css.- The
user-menublock. - The
inputcomponent.
Source
The exact files the CLI installs (app-navbar@1.1.0). View on GitHub · Report an issue
html
<nav class="navbar navbar-expand-lg bootcn-navbar" aria-label="Main">
<div class="container-fluid">
<a class="navbar-brand bootcn-navbar__brand" 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>
<button
class="navbar-toggler bootcn-navbar__toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#bootcn-navbar-menu"
aria-controls="bootcn-navbar-menu"
aria-expanded="false"
aria-label="Toggle navigation"
>
<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>
</button>
<div class="collapse navbar-collapse" id="bootcn-navbar-menu">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link bootcn-navbar__link active" aria-current="page" href="#">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-navbar__link" href="#">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-navbar__link" href="#">Team</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-navbar__link" href="#">Reports</a>
</li>
</ul>
<form class="bootcn-navbar__search" role="search" aria-label="Site" action="#">
<label class="visually-hidden" for="bootcn-navbar-search">Search</label>
<input
class="form-control bootcn-input"
type="search"
id="bootcn-navbar-search"
name="q"
placeholder="Search…"
/>
<button type="submit" class="visually-hidden">Search</button>
</form>
<div class="dropdown bootcn-dropdown bootcn-user-menu">
<button
class="btn bootcn-user-menu__trigger"
type="button"
id="bootcn-navbar-user-trigger"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<span class="bootcn-avatar bootcn-avatar--sm" aria-hidden="true"
><span class="bootcn-avatar__fallback">MP</span></span
>
<span class="bootcn-user-menu__name">Maria Papadopoulou</span>
<svg
class="bootcn-user-menu__chevron"
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="M6 9l6 6 6-6" />
</svg>
</button>
<ul
class="dropdown-menu dropdown-menu-end bootcn-dropdown__menu"
aria-labelledby="bootcn-navbar-user-trigger"
>
<li>
<p class="dropdown-header bootcn-user-menu__header">
<span class="bootcn-user-menu__header-name">Maria Papadopoulou</span>
<span class="bootcn-user-menu__email">maria@example.com</span>
</p>
</li>
<li><hr class="dropdown-divider bootcn-dropdown__divider" /></li>
<li><a class="dropdown-item bootcn-dropdown__item" href="#profile">Profile</a></li>
<li><a class="dropdown-item bootcn-dropdown__item" href="#billing">Billing</a></li>
<li><a class="dropdown-item bootcn-dropdown__item" href="#settings">Settings</a></li>
<li><hr class="dropdown-divider bootcn-dropdown__divider" /></li>
<li>
<button
class="dropdown-item bootcn-dropdown__item bootcn-dropdown__item--destructive"
type="button"
>
Sign out
</button>
</li>
</ul>
</div>
</div>
</div>
</nav>css
.bootcn-navbar {
border-bottom: var(--bootcn-border-width) solid var(--bootcn-border-color);
background-color: var(--bs-body-bg);
}
.bootcn-navbar__brand {
display: inline-flex;
align-items: center;
gap: 0.5rem;
font-weight: 600;
}
.bootcn-navbar__brand .bootcn-icon {
width: 1.25rem;
height: 1.25rem;
}
.bootcn-navbar__toggler {
padding: 0.375rem;
border: var(--bootcn-border-width) solid var(--bootcn-border-color);
border-radius: var(--bootcn-radius);
color: var(--bs-body-color);
}
.bootcn-navbar__toggler .bootcn-icon {
width: 1.25rem;
height: 1.25rem;
}
.bootcn-navbar__toggler:focus {
box-shadow: var(--bootcn-focus-ring);
}
.bootcn-navbar__link {
border-radius: var(--bootcn-radius);
color: var(--bootcn-muted-foreground);
font-size: 0.875rem;
font-weight: 500;
}
.bootcn-navbar__link:hover,
.bootcn-navbar__link.active {
color: var(--bs-emphasis-color);
}
@media (min-width: 992px) {
.bootcn-navbar__link.active {
background-color: var(--bs-secondary-bg);
}
.bootcn-navbar .navbar-nav {
gap: 0.25rem;
}
}
.bootcn-navbar__search {
margin: 0.75rem 0;
}
@media (min-width: 992px) {
.bootcn-navbar__search {
width: 14rem;
margin: 0 0.75rem 0 0;
}
}
