Complete the code to create a navigation section using the correct HTML tag.
<[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 in HTML. It helps browsers and assistive technologies understand the page structure better.
Complete the code to add an accessible label to the navigation element.
<nav aria-[1]="main-nav"> <h2 id="main-nav">Main navigation</h2> <a href="#home">Home</a> <a href="#services">Services</a> <a href="#contact">Contact</a> </nav>
The aria-labelledby attribute is used to provide an accessible name for the navigation region by referencing an element that labels it. Alternatively, aria-label can be used for a direct label.
Fix the error in the navigation list by completing the missing tag.
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
[1]<a href="#contact">Contact</a></li>
</ul>
</nav>- or
Each navigation link inside a list should be wrapped in a <li> (list item) tag. The missing opening <li> tag causes invalid HTML.
Fill both blanks to create a navigation with a heading and a list of links.
<nav aria-[1]="nav-heading"> <h2 id="nav-heading">[2]</h2> <ul> <li><a href="#home">Home</a></li> <li><a href="#blog">Blog</a></li> </ul> </nav>
The aria-labelledby attribute references the heading's id to label the navigation region. The heading text 'Navigation' describes the purpose of the links.
Fill all three blanks to create a responsive navigation with semantic HTML and accessible labeling.
<nav aria-[1]="main-nav"> <h2 id="main-nav">[2]</h2> <ul> <li><a href="[3]">Home</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav>
The aria-labelledby attribute points to the heading with id 'main-nav' which contains the text 'Main Navigation'. The first link uses #home as the href to navigate to the home section.
Practice
<nav> element in HTML?Solution
Step 1: Understand the role of <nav>
The <nav> element is specifically designed to group navigation links.Step 2: Compare with other elements
Other elements like <footer> or <section> serve different purposes, not navigation grouping.Final Answer:
To group the main navigation links on a webpage -> Option CQuick Check:
Navigation grouping = <nav> [OK]
- Confusing <nav> with <footer>
- Using <nav> for non-navigation content
- Thinking <nav> is for styling only
<nav> element?Solution
Step 1: Check the element name
The correct HTML element for navigation is <nav>, not <navigation>.Step 2: Verify proper structure for links
Navigation links are best inside a list (<ul> with <li> and <a> tags) for semantics and accessibility.Final Answer:
<nav><ul><li><a href='#'>Home</a></li></ul></nav> -> Option AQuick Check:
Correct tag + list of links = <nav><ul><li><a href='#'>Home</a></li></ul></nav> [OK]
- Using <navigation> instead of <nav>
- Putting plain text instead of links inside <nav>
- Not using list elements for navigation links
<nav>
<ul>
<li><a href='#home'>Home</a></li>
<li><a href='#about'>About</a></li>
</ul>
</nav>Solution
Step 1: Understand default <ul> and <li> display
By default, <ul> creates a vertical list with bullet points, and <li> items stack vertically.Step 2: Check the <a> tags inside list items
The <a> tags create clickable links labeled 'Home' and 'About'.Final Answer:
A vertical list of clickable links labeled 'Home' and 'About' -> Option DQuick Check:
Default list + links = vertical clickable list [OK]
- Assuming <nav> changes list layout automatically
- Thinking <nav> causes errors with <ul>
- Expecting horizontal menu without CSS
<nav>
<ul>
<li>Home</li>
<li><a href='#about'>About</a></li>
</ul>
</nav>Solution
Step 1: Check each list item content
The first <li> contains plain text 'Home' without a clickable link.Step 2: Confirm proper link usage
Navigation items should be links (<a> tags) for accessibility and functionality.Final Answer:
The first list item 'Home' is missing a link (<a> tag) -> Option AQuick Check:
All nav items need <a> tags [OK]
- Leaving text without <a> inside <li>
- Thinking <nav> disallows <ul> or <li>
- Ignoring missing href attributes
<nav> element?Solution
Step 1: Use <nav> inside <header> for main navigation
Placing <nav> inside <header> groups navigation logically.Step 2: Add
The aria-label 'Main navigation' helps screen readers identify this menu clearly.aria-labelfor accessibilityStep 3: Use list with links inside <nav>
Using <ul> and <li> with <a> tags creates a semantic, accessible menu.Final Answer:
Use <nav> with aria-label and list of links inside header -> Option BQuick Check:
Accessible nav with aria-label = <header> <nav aria-label='Main navigation'> <ul> <li><a href='/home'>Home</a></li> <li><a href='/contact'>Contact</a></li> </ul> </nav> </header> [OK]
- Not using <a> tags for navigation items
- Omitting aria-label for accessibility
- Using plain text instead of links inside <nav>
Ready to prove it?
Pass the test and this pattern moves unknown
