<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Animated SVG Navigation Menu</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
min-height: 100vh;
overflow-x: hidden;
}
.content {
padding: 2rem;
max-width: 800px;
margin: 0 auto;
text-align: center;
animation: fadeIn 1s ease-out;
}
.content h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
}
.content p {
font-size: 1.2rem;
line-height: 1.6;
opacity: 0.9;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
/* Navigation */
.nav-container {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: 1000;
pointer-events: none;
}
.hamburger {
position: absolute;
top: 1.5rem;
left: 1.5rem;
width: 32px;
height: 32px;
cursor: pointer;
pointer-events: all;
z-index: 1001;
transition: transform 0.3s ease;
}
.hamburger:hover {
transform: scale(1.1);
}
.hamburger path {
transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.line {
stroke: #fff;
stroke-width: 3;
stroke-linecap: round;
stroke-linejoin: round;
fill: none;
}
.line1 {
d: path("M 4,7 L 28,7");
transform-origin: 15px 7px;
}
.line2 {
d: path("M 4,16 L 28,16");
transform-origin: 15px 16px;
}
.line3 {
d: path("M 4,25 L 28,25");
transform-origin: 15px 25px;
}
/* Active states for hamburger to X morph */
.nav-container.active .line1 {
transform: rotate(45deg) translate(7px, 7px);
}
.nav-container.active .line2 {
opacity: 0;
transform: scale(0);
}
.nav-container.active .line3 {
transform: rotate(-45deg) translate(8px, -8px);
}
/* Backdrop */
.backdrop {
position: absolute;
inset: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(10px);
opacity: 0;
visibility: hidden;
transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
pointer-events: none;
}
.nav-container.active .backdrop {
opacity: 1;
visibility: visible;
pointer-events: all;
}
/* Menu */
.menu {
position: absolute;
left: 0;
top: 0;
width: min(300px, 80vw);
height: 100vh;
background: rgba(15, 15, 25, 0.98);
backdrop-filter: blur(20px);
transform: translateX(-100%);
transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
pointer-events: none;
}
.nav-container.active .menu {
transform: translateX(0);
pointer-events: all;
}
.menu ul {
list-style: none;
padding: 6rem 2rem 2rem;
height: 100%;
display: flex;
flex-direction: column;
gap: 1rem;
}
.menu li {
opacity: 0;
transform: translateX(-30px);
transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.nav-container.active .menu li {
opacity: 1;
transform: translateX(0);
}
.nav-container.active .menu li:nth-child(1) { transition-delay: 0.1s; }
.nav-container.active .menu li:nth-child(2) { transition-delay: 0.15s; }
.nav-container.active .menu li:nth-child(3) { transition-delay: 0.2s; }
.nav-container.active .menu li:nth-child(4) { transition-delay: 0.25s; }
.nav-container.active .menu li:nth-child(5) { transition-delay: 0.3s; }
.menu a {
display: flex;
align-items: center;
gap: 1rem;
color: #fff;
text-decoration: none;
font-size: 1.1rem;
font-weight: 500;
padding: 0.75rem 1rem;
border-radius: 12px;
transition: all 0.3s ease;
opacity: 0.9;
}
.menu a:hover {
background: rgba(255, 255, 255, 0.1);
opacity: 1;
transform: translateX(8px);
}
.menu svg {
width: 24px;
height: 24px;
flex-shrink: 0;
}
.menu path {
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
fill: none;
}
/* Responsive adjustments */
@media (max-width: 480px) {
.menu {
width: 100vw;
}
.content {
padding: 1rem;
}
}
</style>
</head>
<body>
<div class="nav-container">
<svg class="hamburger" viewBox="0 0 32 32">
<path class="line line1" d="M 4,7 L 28,7" />
<path class="line line2" d="M 4,16 L 28,16" />
<path class="line line3" d="M 4,25 L 28,25" />
</svg>
<div class="backdrop"></div>
<nav class="menu">
<ul>
<li><a href="#home">
<svg viewBox="0 0 24 24">
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
<polyline points="9 22 9 12 15 12 15 22" />
</svg>
<span>Home</span>
</a></li>
<li><a href="#about">
<svg viewBox="0 0 24 24">
<circle cx="12" cy="7" r="4" />
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
</svg>
<span>About</span>
</a></li>
<li><a href="#services">
<svg viewBox="0 0 24 24">
<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.52 6.52a6 6 0 0 1-8.48-8.48l6.52-6.52a6 6 0 0 1 7.94-7.94l-3.77 3.77z" />
</svg>
<span>Services</span>
</a></li>
<li><a href="#portfolio">
<svg viewBox="0 0 24 24">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
<circle cx="8.5" cy="8.5" r="1.5" />
<polyline points="21 15 16 10 5 21" />
</svg>
<span>Portfolio</span>
</a></li>
<li><a href="#contact">
<svg viewBox="0 0 24 24">
<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z" />
<polyline points="22,6 12,13 2,6" />
</svg>
<span>Contact</span>
</a></li>
</ul>
</nav>
</div>
<main class="content">
<h1>Animated SVG Navigation Menu</h1>
<p>
This is a fully animated navigation menu built with SVG for the hamburger icon (morphing to X),
CSS transitions and animations for smooth effects, and vanilla JavaScript for interactivity.
Features include backdrop blur, staggered menu item entrances, hover effects, Escape key/close on click,
and full responsiveness.
</p>
<p style="margin-top: 2rem; opacity: 0.8;">
Click the hamburger menu to open/close. Try resizing, hovering links, or pressing Escape.
</p>
</main>
<script>
const navContainer = document.querySelector('.nav-container');
const hamburger = document.querySelector('.hamburger');
const backdrop = document.querySelector('.backdrop');
const menuLinks = document.querySelectorAll('.menu a');
// Toggle menu on hamburger click
hamburger.addEventListener('click', (e) => {
e.stopPropagation();
navContainer.classList.toggle('active');
});
// Close on backdrop click
backdrop.addEventListener('click', () => {
navContainer.classList.remove('active');
});
// Close on Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
navContainer.classList.remove('active');
}
});
// Close on menu link click
menuLinks.forEach(link => {
link.addEventListener('click', () => {
navContainer.classList.remove('active');
});
});
</script>
</body>
</html>
This is a complete, standalone HTML file demonstrating an animated SVG-based navigation menu. Key features:
- SVG Hamburger Morph: Three SVG paths animate into an "X" using CSS transforms and transitions.
- CSS Animations: Smooth morphing, menu slide-in, staggered list items, backdrop fade/blur, hover effects.
- JavaScript: Toggle functionality, close on backdrop/Escape/link click, no external dependencies.
- Responsive: Adapts to mobile (full-width menu), backdrop blur, modern gradients.
- Accessible: Keyboard-friendly (Escape), semantic HTML.
Copy-paste into a .html file and open in a browser to test!