Site header
A marketing site header: logo, section links and sign-in buttons, collapsing into a menu on phones; sticky with a blurred background.
Installation
bash
npx bootcn add site-headerbash
pnpm dlx bootcn add site-headerbash
yarn dlx bootcn add site-headerbash
bunx --bun bootcn add site-headerThe CLI also installs the design tokens and these blocks and components: button. It prints the <link> and <script> tags to add to your layout.
Usage
Point the links at the sections of your page (id="features"…) or at other pages. On phones the links collapse behind the "Menu" button (Bootstrap's Collapse). The header sticks to the top with a translucent, blurred background; remove position: sticky if you prefer it to scroll away.
Accessibility
- A
<header>landmark holding a<nav aria-label="Main">. - The menu button names itself ("Menu") and reports
aria-expanded. - Links have a visible focus ring; the muted link color keeps 4.5:1.
Dependencies
- Bootstrap 5.3+ CSS and the JS bundle.
themes/tokens/tokens.css.- The
buttoncomponent.
Source
The exact files the CLI installs (site-header@1.0.0). View on GitHub · Report an issue
html
<header class="bootcn-site-header">
<nav class="navbar navbar-expand-md bootcn-site-header__nav" aria-label="Main">
<div class="container bootcn-site-header__inner">
<a class="navbar-brand bootcn-site-header__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-site-header__toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#bootcn-site-header-menu"
aria-controls="bootcn-site-header-menu"
aria-expanded="false"
>
<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>
<span class="visually-hidden">Menu</span>
</button>
<div class="collapse navbar-collapse bootcn-site-header__menu" id="bootcn-site-header-menu">
<ul class="navbar-nav bootcn-site-header__links">
<li class="nav-item">
<a class="nav-link bootcn-site-header__link" href="#features">Features</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-site-header__link" href="#customers">Customers</a>
</li>
<li class="nav-item">
<a class="nav-link bootcn-site-header__link" href="#pricing">Pricing</a>
</li>
<li class="nav-item"><a class="nav-link bootcn-site-header__link" href="#faq">FAQ</a></li>
</ul>
<div class="bootcn-site-header__actions">
<a class="btn bootcn-button bootcn-button--ghost" href="#sign-in">Sign in</a>
<a class="btn bootcn-button bootcn-button--default" href="#sign-up">Get started</a>
</div>
</div>
</div>
</nav>
</header>css
.bootcn-site-header {
position: sticky;
z-index: 1030;
top: 0;
border-bottom: var(--bootcn-border-width) solid var(--bootcn-border-color);
background-color: rgba(var(--bs-body-bg-rgb), 0.85);
backdrop-filter: saturate(180%) blur(8px);
}
.bootcn-site-header__nav {
padding-block: 0.625rem;
}
.bootcn-site-header__brand {
display: inline-flex;
align-items: center;
gap: 0.5rem;
color: var(--bootcn-foreground);
font-size: 1rem;
font-weight: 700;
}
.bootcn-site-header__brand:hover {
color: var(--bootcn-foreground);
}
.bootcn-site-header__brand .bootcn-icon {
width: 1.25rem;
height: 1.25rem;
}
.bootcn-site-header__toggler {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2.25rem;
height: 2.25rem;
padding: 0;
border: var(--bootcn-border-width) solid var(--bootcn-border-color);
border-radius: var(--bootcn-radius);
color: var(--bootcn-foreground);
}
.bootcn-site-header__toggler:focus {
box-shadow: var(--bootcn-focus-ring);
}
.bootcn-site-header__link {
color: var(--bootcn-muted-foreground);
font-size: 0.875rem;
font-weight: 500;
}
.bootcn-site-header__link:hover,
.bootcn-site-header__link:focus-visible {
color: var(--bootcn-foreground);
}
.bootcn-site-header__link:focus-visible {
border-radius: var(--bootcn-radius-sm);
box-shadow: var(--bootcn-focus-ring);
}
.bootcn-site-header__actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
padding-block: 0.75rem 0.25rem;
}
@media (min-width: 768px) {
.bootcn-site-header__links {
margin-inline: 2rem auto;
}
.bootcn-site-header__actions {
padding: 0;
}
}
