Ask any question about HTML here... and get an instant response.
How do I create a responsive navigation bar using HTML?
Asked on Dec 07, 2025
Answer
To create a responsive navigation bar, you can use the
<nav> element combined with CSS for styling and media queries for responsiveness. Below is a basic example of how you can structure a responsive navigation bar.
<!-- BEGIN COPY / PASTE -->
<nav>
<ul class="navbar">
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
<style>
.navbar {
list-style-type: none;
padding: 0;
display: flex;
justify-content: space-around;
background-color: #333;
}
.navbar li {
display: inline;
}
.navbar a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
@media (max-width: 600px) {
.navbar {
flex-direction: column;
}
}
</style>
<!-- END COPY / PASTE -->Additional Comment:
- The
<nav>element is used to define a set of navigation links. - Flexbox is utilized for layout, making it easy to switch between horizontal and vertical orientations.
- Media queries adjust the layout for smaller screens, ensuring the navigation bar remains user-friendly.
- Ensure links have sufficient padding for easy tapping on mobile devices.
✅ Answered with HTML best practices.
Recommended Links:
