Ask any question about HTML here... and get an instant response.
How do I create a responsive navigation menu using only HTML and CSS?
Asked on Nov 17, 2025
Answer
To create a responsive navigation menu using only HTML and CSS, you can use a combination of semantic HTML elements and CSS media queries. This allows the menu to adapt to different screen sizes without relying on JavaScript.
<!-- BEGIN COPY / PASTE -->
<nav>
<ul class="nav-menu">
<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>
.nav-menu {
list-style-type: none;
padding: 0;
display: flex;
justify-content: space-around;
}
.nav-menu li {
margin: 0 10px;
}
.nav-menu a {
text-decoration: none;
color: black;
padding: 8px 16px;
display: block;
}
@media (max-width: 600px) {
.nav-menu {
flex-direction: column;
align-items: center;
}
}
</style>
<!-- END COPY / PASTE -->Additional Comment:
- The
<nav>element is used to define a set of navigation links. - CSS Flexbox is utilized to create a flexible and adaptive layout for the menu items.
- Media queries adjust the layout for smaller screens, stacking menu items vertically.
✅ Answered with HTML best practices.
Recommended Links:
