Bird
Raised Fist0
HTMLmarkup~5 mins

Navigation structure basics in HTML

Choose your learning style10 modes available
Introduction

Navigation helps people move around a website easily. It shows links to important pages so visitors don't get lost.

When you want to create a menu for your website.
When you need to help users find different sections quickly.
When building a header with links to main pages.
When organizing links in a sidebar or footer.
When improving website accessibility for keyboard users.
Syntax
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.

Examples
A simple navigation menu with links to sections on the same page.
HTML
<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>
Navigation with an ARIA label to help screen readers understand its purpose.
HTML
<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>
Navigation using inline links separated by vertical bars for a simple horizontal menu.
HTML
<nav>
  <a href="index.html">Home</a> |
  <a href="blog.html">Blog</a> |
  <a href="about.html">About</a>
</nav>
Sample Program

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.

HTML
<!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>
OutputSuccess
Important Notes

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.

Summary

Navigation helps users find pages easily.

Use <nav> with lists of links for clear structure.

Make navigation accessible and responsive for all users.

Practice

(1/5)
1. What is the main purpose of the <nav> element in HTML?
easy
A. To define a section of navigation links
B. To add images to the page
C. To create a footer area
D. To style text with bold font

Solution

  1. Step 1: Understand the role of <nav>

    The <nav> element is designed to group navigation links on a webpage.
  2. Step 2: Compare with other options

    Options A, B, and D describe unrelated HTML functions like footers, images, or text styling.
  3. Final Answer:

    To define a section of navigation links -> Option A
  4. Quick Check:

    Navigation = <nav> section [OK]
Hint: Remember: <nav> groups navigation links only [OK]
Common Mistakes:
  • Confusing <nav> with <footer>
  • Thinking <nav> adds images
  • Using <nav> for styling text
2. Which of the following is the correct way to start a navigation section in HTML?
easy
A. <navigation>
B.
C. <nav>
D.

Solution

  1. Step 1: Recall the correct HTML tag for navigation

    The official HTML5 tag for navigation is <nav>.
  2. Step 2: Check other options for validity

    Tags like <navigation>, <nav-section>, and <nav-area> are not valid HTML tags.
  3. Final Answer:

    <nav> -> Option C
  4. Quick Check:

    Correct tag = <nav> [OK]
Hint: Use exactly <nav> to start navigation [OK]
Common Mistakes:
  • Using non-standard tags like <navigation>
  • Adding extra words in tag names
  • Confusing with other section tags
3. What will the following HTML code display in a browser?
<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>
medium
A. A form with input fields
B. A list of clickable links labeled Home, About, Contact
C. An error message in the browser
D. Plain text showing the HTML code

Solution

  1. Step 1: Understand the HTML structure

    The code uses <nav> with an unordered list <ul> containing list items <li> each with a link <a>.
  2. Step 2: Predict the browser rendering

    The browser will show a vertical list of clickable links labeled Home, About, and Contact.
  3. Final Answer:

    A list of clickable links labeled Home, About, Contact -> Option B
  4. Quick Check:

    Navigation list = clickable links [OK]
Hint: Lists inside <nav> create clickable menus [OK]
Common Mistakes:
  • Thinking code shows as text
  • Expecting a form instead of links
  • Assuming browser error
4. Identify the error in this navigation HTML code:
<nav>
  <ul>
    <li><a href='home.html'>Home</li>
    <li><a href='about.html'>About</a></li>
  </ul>
</nav>
medium
A. Missing closing </a> tag for the Home link
B. The <ul> tag is not allowed inside <nav>
C. The <li> tags should be replaced with <div>
D. The href attribute should not have quotes

Solution

  1. 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>.
  2. Step 2: Validate other tags and attributes

    The <ul> inside <nav> is valid, <li> is correct, and href values should be quoted.
  3. Final Answer:

    Missing closing </a> tag for the Home link -> Option A
  4. Quick Check:

    Anchor tags must close properly [OK]
Hint: Every needs a closing before [OK]
Common Mistakes:
  • Forgetting to close <a> tags
  • Thinking <ul> is invalid inside <nav>
  • Removing quotes from href
5. You want to create a navigation bar that is accessible and responsive. Which combination of HTML and CSS practices is best?
hard
A. Use <header> only, no lists, and inline styles for positioning
B. Use <div> with <p> tags for links, no ARIA, and float for layout
C. Use <nav> with <span> for links, no semantic tags, and fixed widths
D. Use <nav> with a <ul> of links, add ARIA labels, and style with Flexbox for layout

Solution

  1. Step 1: Identify semantic HTML for navigation

    The <nav> element with a list (<ul>) of links is the correct semantic structure.
  2. 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.
  3. Final Answer:

    Use <nav> with a <ul> of links, add ARIA labels, and style with Flexbox for layout -> Option D
  4. Quick Check:

    Semantic + ARIA + Flexbox = best practice [OK]
Hint: Combine semantic tags, ARIA, and Flexbox for best navigation [OK]
Common Mistakes:
  • Using non-semantic tags for navigation
  • Ignoring accessibility with ARIA
  • Using outdated float instead of Flexbox
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard