A responsive navigation bar is a key element in modern website design. Whether you're building a personal blog, portfolio, or business site, having a navigation bar that adapts to all screen sizes is essential. In this tutorial, you'll learn how to build a responsive navigation bar with a hamburger menu using only HTML and CSS — perfect for beginners!
Why a Responsive Navigation Bar Matters
A responsive navbar improves user experience on mobile devices, reduces bounce rates, and increases your website's overall usability. As more people browse the internet on their phones, having a mobile-friendly navigation menu is no longer optional—it’s a necessity.
What You'll Learn
-
How to structure your navigation bar with HTML
-
How to style it for desktop and mobile using CSS
-
How to create a hamburger menu icon
-
How to toggle the menu on smaller screens (using CSS only!)
HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Navbar</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav>
<ul class="sidebar">
<li onclick=hideSidebar()><a href="#"><svg xmlns="http://www.w3.org/2000/svg" height="26" viewBox="0 96 960 960" width="26"><path d="m249 849-42-42 231-231-231-231 42-42 231 231 231-231 42 42-231 231 231 231-42 42-231-231-231 231Z"/></svg></a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Forum</a></li>
<li><a href="#">Login</a></li>
</ul>
<ul>
<li><a href="#">Mirox Dev</a></li>
<li class="hideOnMobile"><a href="#">Blog</a></li>
<li class="hideOnMobile"><a href="#">Products</a></li>
<li class="hideOnMobile"><a href="#">About</a></li>
<li class="hideOnMobile"><a href="#">Forum</a></li>
<li class="hideOnMobile"><a href="#">Login</a></li>
<li class="menu-button" onclick=showSidebar()><a href="#"><svg xmlns="http://www.w3.org/2000/svg" height="26" viewBox="0 96 960 960" width="26"><path d="M120 816v-60h720v60H120Zm0-210v-60h720v60H120Zm0-210v-60h720v60H120Z"/></svg></a></li>
</ul>
</nav>
<script>
function showSidebar(){
const sidebar = document.querySelector('.sidebar')
sidebar.style.display = 'flex'
}
function hideSidebar(){
const sidebar = document.querySelector('.sidebar')
sidebar.style.display = 'none'
}
</script>
</body>
</html>
CSS Code
*{
margin: 0;
padding: 0;
}
body{
min-height: 100vh;
background:linear-gradient(#7F66FF,#3240E1) ;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
nav{
background-color: white;
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.1);
}
nav ul{
width: 100%;
list-style: none;
display: flex;
justify-content: flex-end;
align-items: center;
}
nav li{
height: 50px;
}
nav a{
height: 100%;
padding: 0 30px;
text-decoration: none;
display: flex;
align-items: center;
color: black;
}
nav a:hover{
background-color: #f0f0f0;
}
nav li:first-child{
margin-right: auto;
}
.sidebar{
position: fixed;
top: 0;
right: 0;
height: 100vh;
width: 250px;
background-color: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(12px);
box-shadow: -10px 0 10px rgba(0, 0, 0, 0.1);
list-style: none;
display: none;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
}
.sidebar li{
width: 100%;
}
.sidebar a{
width: 100%;
}
.menu-button{
display: none;
}
@media(max-width: 800px){
.hideOnMobile{
display: none;
}
.menu-button{
display: block;
}
}
@media(max-width: 400px){
.sidebar{
width: 100%;
}
}
Final Result
By the end of this tutorial, you'll have a fully functional, responsive navbar that looks great on both desktop and mobile screens.
More Tutorials
Want more beginner-friendly web design tutorials?
👉 https://youtube.com/@miroxdev?si=s2dGLLayQJcvwjxj
Don’t forget to subscribe and leave a comment if you found the tutorial helpful!
Conclusion
A responsive navigation bar with a hamburger menu is one of the most useful features you can add to your website. It makes your site more accessible, modern, and mobile-friendly. With just HTML and CSS, you can achieve a professional look in no time.
Stay tuned for more tutorials and design tips every week!
