Resize your browser to see the mobile menu in action!
Try resizing your browser window to less than 768px wide,
or use your browser's mobile device simulator (F12 > toggle device toolbar)
A responsive navbar has three main parts:
1. The HTML structure - Logo, hamburger button, and nav links
2. CSS media queries - Different styles for mobile vs desktop
3. JavaScript - Toggle the menu open/closed on mobile
On desktop, the hamburger is hidden and links display horizontally:
On screens smaller than 768px, we show the hamburger and hide the links:
A simple function to add/remove the "active" class:
.active is added. Check the CSS above to see how!
@media (max-width: 768px) - Styles only apply when screen is 768px or smaller
position: fixed - Keeps navbar at top even when scrolling
display: flex - Arranges items in a row (or column with flex-direction)
classList.toggle() - Adds class if missing, removes if present
z-index: 1000 - Keeps navbar above other content
1. Change the breakpoint from 768px to 1024px
2. Add a background color change when scrolling
3. Add smooth slide-down animation for the mobile menu
4. Make the links close the menu when clicked