Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Lesson 4 of 9
Navigation Menu Patterns
Navigation menus are the most important UI component on any website. Professional navigation is built using the semantic <nav> element containing an unordered list (<ul>) of links. This pattern is the industry standard because it is accessible, SEO-friendly, and CSS-flexible.
Building Navigation with <nav>
The <nav> element marks a section as navigation. Screen readers treat it as a 'landmark'.
Key rules:
1. Use <nav> for major navigation blocks only.
2. Use aria-label to distinguish multiple <nav> elements.
3. Use aria-current="page" on the current page link.
4. Use <ul> + <li> inside <nav>.
5. CSS transforms the list into a horizontal bar with display: flex.
Proper semantic markup makes navigation menus accessible to screen readers
Navigation Example
<!DOCTYPE html>
<html>
<head>
<style>
nav ul { list-style: none; padding: 0; margin: 0; display: flex; background: #333; }
nav a { display: block; padding: 14px 20px; color: white; text-decoration: none; }
nav a:hover { background: #555; }
nav a[aria-current="page"] { background: #229c6b; font-weight: bold; }
</style>
</head>
<body>
<nav aria-label="Main navigation">
<ul>
<li><a href="/" aria-current="page">Home</a></li>
<li><a href="/courses">Courses</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
<main style="padding:20px">
<h1>Welcome to My Website</h1>
</main>
</body>
</html>Try It Yourself: Navigation
Quick Quiz
Finished this lesson?