Back to Tutorials
Web Development
20 min read
Sahasransu Satpathy
1/15/2026
How to Make a Responsive Navigation Bar
Step-by-step guide to creating a fully responsive navigation bar using HTML, CSS, and JavaScript
Introduction
A responsive navigation bar (navbar) adapts to different screen sizes. This tutorial shows you how to build a modern, mobile-friendly navbar with HTML, CSS, and a touch of JavaScript.
Step 1: HTML Structure
Create the basic HTML structure:
<nav class="navbar">
<div class="brand">MyWebsite</div>
<button class="toggle-button">
☰
</button>
<div class="navbar-links">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</nav>
Step 2: CSS Styling
Style the navbar for desktop and mobile:
body {
margin: 0;
font-family: Arial, sans-serif;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #4CAF50;
padding: 10px 20px;
}
.navbar .brand {
color: white;
font-size: 24px;
font-weight: bold;
}
.navbar-links ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
.navbar-links li {
margin-left: 20px;
}
.navbar-links a {
text-decoration: none;
color: white;
font-size: 18px;
}
.toggle-button {
display: none;
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
}
/* Mobile Styles */
@media (max-width: 768px) {
.toggle-button {
display: block;
}
.navbar-links {
display: none;
width: 100%;
}
.navbar-links ul {
flex-direction: column;
}
.navbar-links li {
margin: 10px 0;
}
.navbar-links.active {
display: flex;
}
}
Step 3: JavaScript for Toggle
Make the navbar toggle on mobile screens:
const toggleButton = document.querySelector('.toggle-button');
const navbarLinks = document.querySelector('.navbar-links');
toggleButton.addEventListener('click', () => {
navbarLinks.classList.toggle('active');
});
Step 4: Testing
- Open your HTML file in a browser.
- Resize the window to see the navbar adapt.
- Click the toggle button on mobile view to expand/collapse links.
Step 5: Enhancements
- Add smooth transitions with CSS.
- Highlight active links.
- Include dropdown menus if needed.
Conclusion
You now have a fully responsive navigation bar that works across desktop and mobile devices. Customize colors, fonts, and layout to match your website’s theme.
SEO Suggestions:
- Main keywords: responsive navbar tutorial, create navigation bar, mobile-friendly navbar, HTML CSS JS navbar
- Meta description: Learn how to make a responsive navigation bar using HTML, CSS, and JavaScript. Step-by-step guide for mobile-friendly websites.
- Catchy title suggestions: "How to Make a Responsive Navigation Bar – Step-by-Step Guide", "Build a Mobile-Friendly Navbar Easily"
Previous Tutorial
Browse All TutorialsNext Tutorial
Browse All Tutorials