Quiz Entry - updated: 2026.07.14
How do you create a hamburger menu for mobile with W3.CSS?
Hide the full menu on phones with w3-hide-small, then show a hamburger button that toggles the w3-hide class on a dropdown to reveal those items.
<div class="w3-bar w3-blue">
<a href="#" class="w3-bar-item w3-button">News</a>
<a href="#" class="w3-bar-item w3-button w3-hide-small">Login</a>
<a href="#" class="w3-bar-item w3-button w3-hide-small">About</a>
<button class="w3-bar-item w3-button w3-right w3-hide-large w3-hide-medium"
onclick="document.getElementById('sub').classList.toggle('w3-hide')">
☰
</button>
</div>
<div id="sub" class="w3-bar-block w3-blue w3-hide">
<a href="#" class="w3-bar-item w3-button">Login</a>
<a href="#" class="w3-bar-item w3-button">About</a>
</div>
Key classes:
| Class | Effect |
|---|---|
w3-hide-small |
Hidden on small screens |
w3-hide-medium |
Hidden on medium screens |
w3-hide-large |
Hidden on large screens |
w3-hide |
Hidden on all sizes |
The pattern:
- Hide menu items on small screens
- Show hamburger button (☰) only on small screens
- Toggle
w3-hideclass on click to show/hide dropdown