Complete the code to create a navigation bar using the correct HTML element.
<[1]> <a href="#home">Home</a> <a href="#about">About</a> <a href="#contact">Contact</a> </[1]>
The <nav> element is used to define a block of navigation links. It helps browsers and assistive technologies understand the page structure.
Complete the code to add a navigation list inside the nav element.
<nav>
<ul>[1]</ul>
</nav>- without
- .
tags instead of list items.
Navigation links are often grouped inside an unordered list <ul> with each link inside a list item <li>. This helps screen readers and organizes the links clearly.
Fix the error in the navigation code by completing the blank with the correct attribute for links.
<nav>
<ul>
<li><a [1]>Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>The href attribute specifies the link's destination. Using other attributes like src, link, or url will not work for anchor tags.
Fill both blanks to create a navigation bar with accessible labels and semantic structure.
<[1] aria-label="Main navigation"> <[2]> <li><a href="#home">Home</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </[2]> </[1]>
- for the list of links.
The outer element should be <nav> for navigation. Inside it, the list of links should be inside an unordered list <ul>. The aria-label helps screen readers understand the navigation purpose.
Fill all three blanks to create a responsive navigation bar with semantic HTML and accessible links.
<[1] aria-label="Primary navigation"> <[2] class="menu"> <li><a href="#home" [3]>Home</a></li> <li><a href="#blog">Blog</a></li> <li><a href="#contact">Contact</a></li> </[2]> </[1]>
The navigation container is <nav>. The list of links is inside an unordered list <ul>. The aria-current="page" attribute marks the current page link for screen readers.
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
