Navigation is the first thing users interact with — and the first thing developers copy-paste without thinking. This guide covers 30 responsive navbar patterns in HTML and CSS, from the simplest horizontal nav to accessible mega menus and glassmorphism headers.
üîó Interactive version with live nav demos: uixdraft.com/responsive-navbar-html-css
The Foundation: Responsive Navbar Pattern
Every responsive navbar follows this structure:
<nav class="navbar">
<a href="/" class="logo">Brand</a>
<button class="hamburger" id="hamburger"
aria-label="Toggle menu" aria-expanded="false">
<span></span><span></span><span></span>
</button>
<ul class="nav-links" id="nav-menu">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
<a href="/signup" class="nav-cta">Get Started</a>
</nav>
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
height: 64px;
background: #0d1117;
position: sticky; top: 0; z-index: 100;
}
.logo { font-weight: 800; color: #f1f5f9; text-decoration: none; }
.nav-links { display: flex; gap: 28px; list-style: none; }
.nav-links a { color: rgba(241,245,249,.6); text-decoration: none; }
.nav-links a:hover { color: #f1f5f9; }
.hamburger { display: none; }
@media (max-width: 768px) {
.hamburger { display: flex; flex-direction: column; gap: 5px; }
.nav-links { display: none; }
.nav-links.open { display: flex; flex-direction: column; width: 100%; }
}
const btn = document.getElementById('hamburger');
const menu = document.getElementById('nav-menu');
btn.addEventListener('click', () => {
const open = menu.classList.toggle('open');
btn.setAttribute('aria-expanded', open);
});
1. Sticky Navbar with Backdrop Blur
Pins to the top, frosted glass background on scroll:
.sticky-nav {
position: sticky;
top: 0; z-index: 100;
background: rgba(13, 17, 23, 0.92);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-bottom: 1px solid rgba(255,255,255,.07);
}
2. Glassmorphism Floating Navbar
Floats above the page with a glass effect:
.glass-nav {
position: fixed;
top: 16px; left: 50%;
transform: translateX(-50%);
width: calc(100% - 48px);
max-width: 1000px;
background: rgba(255, 255, 255, 0.06);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 14px;
z-index: 100;
}
3. Transparent Hero Navbar (Gains BG on Scroll)
.hero-nav {
position: fixed; top: 0; left: 0; right: 0;
background: transparent;
transition: background 0.3s, box-shadow 0.3s;
}
.hero-nav.scrolled {
background: rgba(13, 17, 23, 0.95);
box-shadow: 0 1px 0 rgba(255,255,255,.07);
}
window.addEventListener('scroll', () => {
document.querySelector('.hero-nav')
.classList.toggle('scrolled', window.scrollY > 60);
});
4. Scroll-Shrink Navbar
Height reduces as the user scrolls:
.nav-shrink {
height: 72px;
transition: height 0.3s ease;
}
.nav-shrink.scrolled { height: 48px; }
window.addEventListener('scroll', () => {
document.querySelector('.nav-shrink')
.classList.toggle('scrolled', window.scrollY > 80);
});
5. CSS-Only Hamburger Menu (No JavaScript)
Pure CSS toggle using a hidden checkbox:
<input type="checkbox" id="nav-toggle" hidden>
<label for="nav-toggle" class="hamburger">
<span></span><span></span><span></span>
</label>
<ul class="nav-links">...</ul>
/* Show menu when checkbox is checked */
#nav-toggle:checked ~ .nav-links { display: flex; flex-direction: column; }
/* Animate bars to √ó */
#nav-toggle:checked ~ .hamburger span:nth-child(1) {
transform: rotate(45deg) translate(5px, 5px);
}
#nav-toggle:checked ~ .hamburger span:nth-child(2) { opacity: 0; }
#nav-toggle:checked ~ .hamburger span:nth-child(3) {
transform: rotate(-45deg) translate(5px, -5px);
}
6. Slide-in Drawer (Off-Canvas)
.drawer {
position: fixed; top: 0; left: 0;
width: 280px; height: 100vh;
background: #161b22;
transform: translateX(-100%);
transition: transform 0.25s ease;
z-index: 200; padding: 24px 20px;
}
.drawer.open { transform: translateX(0); }
.overlay {
position: fixed; inset: 0;
background: rgba(0,0,0,.5);
display: none; z-index: 199;
}
.overlay.show { display: block; }
7. CSS Dropdown Menu
.has-dropdown { position: relative; }
.dropdown {
position: absolute; top: 100%; left: 0;
min-width: 200px;
background: #161b22;
border: 1px solid rgba(255,255,255,.1);
border-radius: 10px; padding: 6px;
list-style: none;
visibility: hidden; opacity: 0;
transform: translateY(-6px);
transition: all 0.2s ease;
}
/* Trigger on hover AND keyboard focus */
.has-dropdown:hover .dropdown,
.has-dropdown:focus-within .dropdown {
visibility: visible; opacity: 1;
transform: translateY(4px);
}
8. Bottom Tab Navigation (Mobile)
.bottom-nav {
position: fixed; bottom: 0; left: 0; right: 0;
display: flex; height: 64px;
background: #0d1117;
border-top: 1px solid rgba(255,255,255,.07);
}
.tab-item {
flex: 1; display: flex; flex-direction: column;
align-items: center; justify-content: center; gap: 3px;
}
.tab-item.active .tab-label { color: #a78bfa; font-weight: 700; }
Accessibility Checklist for Navbars
Always include these for production:
- ‚úÖ
aria-label="Main navigation"on<nav> - ‚úÖ
aria-expanded="false/true"on hamburger button - ‚úÖ
aria-controls="menu-id"pointing to the menu - ‚úÖ
aria-current="page"on the active link - ‚úÖ
:focus-visiblestyles — neveroutline: nonewithout a replacement - ✅ Keyboard navigable dropdowns (
:focus-within) - ‚úÖ Skip-to-content link as the first focusable element
<!-- First element in <body> -->
<a href="#main-content" class="skip-link">Skip to content</a>
.skip-link {
position: absolute; top: -40px; left: 0;
background: #a78bfa; color: #06080f;
padding: 8px 16px; z-index: 9999;
}
.skip-link:focus { top: 0; }
All 30 Navbar Patterns
The complete collection — including mega menus, animated X hamburger, progress-aware sticky nav, vertical sidebar nav, breadcrumbs, and docs sidebar — is at:
üëâ uixdraft.com/responsive-navbar-html-css
More CSS references: CSS Buttons (50 styles) · CSS Grid (35 patterns) · CSS Animations (40 demos)
United States
NORTH AMERICA
Related News
Secret Claude Tracker Shocks Users After Anthropic's Anti-Surveillance Stance
12h ago
EV Batteries Defy Expectations, Last Hundreds of Thousands of Miles
1d ago
GBase 8a Performance Anomaly Case Study: How a Single Parameter Change Sparked a Chain Reaction
1d ago
Who Else Has Inherited a Codebase With Zero Comments and a Prayer?
1d ago
完美的平庸
3h ago