Ask any question about HTML here... and get an instant response.
How can I create a responsive menu for mobile devices using HTML?
Asked on Dec 03, 2025
Answer
To create a responsive menu for mobile devices using HTML, you can utilize the
<nav> element along with some simple CSS for styling. A common approach is to use a "hamburger" icon that toggles the visibility of the menu on smaller screens.
<!-- BEGIN COPY / PASTE -->
<nav>
<button class="menu-toggle">☰</button>
<ul class="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>
.menu {
display: none;
}
.menu-toggle {
display: block;
}
@media (min-width: 600px) {
.menu {
display: block;
}
.menu-toggle {
display: none;
}
}
</style>
<script>
document.querySelector('.menu-toggle').addEventListener('click', function() {
const menu = document.querySelector('.menu');
menu.style.display = menu.style.display === 'block' ? 'none' : 'block';
});
</script>
<!-- END COPY / PASTE -->Additional Comment:
- The
<nav>element is used to define a set of navigation links. - The "hamburger" icon is a common UI pattern for toggling menus on mobile devices.
- Media queries in CSS help to adjust the display based on screen size.
- JavaScript is used to toggle the menu's visibility on smaller screens.
✅ Answered with HTML best practices.
Recommended Links:
