Navigation helps people move around a website easily. It shows links to important pages so visitors don't get lost.
Navigation structure basics in HTML
<nav> <ul> <li><a href="page1.html">Page 1</a></li> <li><a href="page2.html">Page 2</a></li> <li><a href="page3.html">Page 3</a></li> </ul> </nav>
The <nav> tag defines a navigation section.
Use <ul> and <li> to list links clearly.
<nav> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav>
<nav aria-label="Main navigation"> <ul> <li><a href="index.html">Home</a></li> <li><a href="services.html">Services</a></li> <li><a href="contact.html">Contact</a></li> </ul> </nav>
<nav> <a href="index.html">Home</a> | <a href="blog.html">Blog</a> | <a href="about.html">About</a> </nav>
This example shows a navigation bar at the top with three links. The links use clear text and good color contrast. The navigation uses semantic tags and an ARIA label for accessibility. The menu is horizontal and spaced nicely using CSS Flexbox.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Simple Navigation Example</title> <style> nav { background-color: #004080; padding: 1rem; } nav ul { list-style: none; display: flex; gap: 1.5rem; margin: 0; padding: 0; } nav a { color: white; text-decoration: none; font-weight: bold; } nav a:hover, nav a:focus { text-decoration: underline; outline: none; } </style> </head> <body> <header> <nav aria-label="Primary navigation"> <ul> <li><a href="#home">Home</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> </header> <main> <section id="home"> <h1>Welcome to Our Website</h1> <p>This is the home section.</p> </section> <section id="services"> <h2>Our Services</h2> <p>Details about services offered.</p> </section> <section id="contact"> <h2>Contact Us</h2> <p>How to get in touch.</p> </section> </main> </body> </html>
Always use the <nav> element for main navigation to help screen readers.
Use clear link text that tells users where the link goes.
Make sure navigation works well on small screens by using flexible layouts like Flexbox.
Navigation helps users find pages easily.
Use <nav> with lists of links for clear structure.
Make navigation accessible and responsive for all users.
Practice
<nav> element in HTML?Solution
Step 1: Understand the role of
The<nav><nav>element is designed to group navigation links on a webpage.Step 2: Compare with other options
Options A, B, and D describe unrelated HTML functions like footers, images, or text styling.Final Answer:
To define a section of navigation links -> Option AQuick Check:
Navigation = <nav> section [OK]
- Confusing <nav> with <footer>
- Thinking <nav> adds images
- Using <nav> for styling text
Solution
Step 1: Recall the correct HTML tag for navigation
The official HTML5 tag for navigation is<nav>.Step 2: Check other options for validity
Tags like<navigation>,<nav-section>, and<nav-area>are not valid HTML tags.Final Answer:
<nav> -> Option CQuick Check:
Correct tag = <nav> [OK]
- Using non-standard tags like <navigation>
- Adding extra words in tag names
- Confusing with other section tags
<nav>
<ul>
<li><a href='#home'>Home</a></li>
<li><a href='#about'>About</a></li>
<li><a href='#contact'>Contact</a></li>
</ul>
</nav>Solution
Step 1: Understand the HTML structure
The code uses<nav>with an unordered list<ul>containing list items<li>each with a link<a>.Step 2: Predict the browser rendering
The browser will show a vertical list of clickable links labeled Home, About, and Contact.Final Answer:
A list of clickable links labeled Home, About, Contact -> Option BQuick Check:
Navigation list = clickable links [OK]
- Thinking code shows as text
- Expecting a form instead of links
- Assuming browser error
<nav>
<ul>
<li><a href='home.html'>Home</li>
<li><a href='about.html'>About</a></li>
</ul>
</nav>Solution
Step 1: Check the anchor tags inside list items
The first list item has<a href='home.html'>but no closing</a>before the</li>.Step 2: Validate other tags and attributes
The<ul>inside<nav>is valid,<li>is correct, and href values should be quoted.Final Answer:
Missing closing </a> tag for the Home link -> Option AQuick Check:
Anchor tags must close properly [OK]
- Forgetting to close <a> tags
- Thinking <ul> is invalid inside <nav>
- Removing quotes from href
Solution
Step 1: Identify semantic HTML for navigation
The<nav>element with a list (<ul>) of links is the correct semantic structure.Step 2: Accessibility and responsive layout
Adding ARIA labels improves accessibility. Using Flexbox in CSS helps create a responsive layout that adapts to screen sizes.Final Answer:
Use <nav> with a <ul> of links, add ARIA labels, and style with Flexbox for layout -> Option DQuick Check:
Semantic + ARIA + Flexbox = best practice [OK]
- Using non-semantic tags for navigation
- Ignoring accessibility with ARIA
- Using outdated float instead of Flexbox
Ready to prove it?
Pass the test and this pattern moves unknown
