HTML 14 ๐๏ธ How to HTML nav Semantic element
How-To: Use <nav> for Primary Site Navigation
Steps:
- Wrap your main navigation links in a
<nav>element. - Use semantic HTML like
<ul>or<ol>inside<nav>. - Add
role="navigation"andaria-labelfor accessibility.
Example:
<nav role="navigation" aria-label="Main site navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
How-To: Add Accessibility Labels to <nav>
Steps:
- Use
aria-labelto describe the purpose of the nav block. - Include descriptive text if visual labels are not visible.
Example:
<nav aria-label="Main navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
</ul>
</nav>
How-To: Create a Responsive Mobile Menu with <nav>
Steps:
- Add a toggle button for mobile.
- Use
aria-controlsto link the button to the menu. - Apply CSS for hiding/showing the menu on small screens.
Example:
<nav role="navigation" aria-label="Main navigation">
<button class="nav-toggle" aria-expanded="false" aria-controls="main-menu">Menu</button>
<ul id="main-menu" class="nav-menu">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
How-To: Use Multiple <nav> Elements in One Page
Steps:
- Place each navigation section within its own
<nav>. - Give each one a unique
aria-labelfor clarity. - Use semantic context (e.g., main, sidebar, article).
Example:
<header>
<nav aria-label="Main site navigation">
<ul><li><a href="/">Home</a></li></ul>
</nav>
</header>
<aside>
<nav aria-label="Sidebar links">
<ul><li><a href="/faq">FAQ</a></li></ul>
</nav>
</aside>
How-To: Build a Tab-Based Navigation Using <nav>
Steps:
- Use a container with
role="tablist". - Each tab is a button with
role="tab". - Ensure proper
aria-selectedstates.
Example:
<nav role="navigation" aria-label="Tab navigation">
<div class="tabs">
<button role="tab" aria-selected="true">Profile</button>
<button role="tab">Settings</button>
</div>
</nav>
How-To: Implement Breadcrumb Navigation Using <nav>
Steps:
- Wrap the breadcrumb in a
<nav>element. - Use
aria-label="Breadcrumb"for screen readers. - Structure using an ordered list (
<ol>).
Example:
<nav aria-label="Breadcrumb">
<ol>
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
<li>Web Development</li>
</ol>
</nav>
How-To: Style <nav> Without Changing Semantic Meaning
Steps:
- Apply CSS styles directly to the
<nav>or child elements. - Maintain focus visibility and contrast for accessibility.
- Ensure responsive behavior for mobile views.
Example:
nav ul {
list-style: none;
display: flex;
}
nav a {
padding: 10px;
text-decoration: none;
}
How-To: Add Meaningful Link Text in <nav>
Steps:
- Avoid generic phrases like โClick hereโ.
- Use descriptive anchor texts that indicate destination.
Example:
<nav>
<ul>
<li><a href="/services/web-design">Web Design Services</a></li>
<li><a href="/support/help">Get Help</a></li>
</ul>
</nav>
How-To: Include Dropdown Menus in Semantic <nav>
Steps:
- Use nested
<ul>inside<li>for submenus. - Add
aria-haspopup="true"andaria-expandedattributes. - Ensure keyboard accessibility.
Example:
<nav role="navigation" aria-label="Site navigation">
<ul>
<li class="dropdown">
<a href="/products">Products</a>
<ul class="sub-menu">
<li><a href="/web-dev">Web Development</a></li>
</ul>
</li>
</ul>
</nav>
How-To: Implement Pagination Using <nav>
Steps:
- Wrap pagination with
<nav>. - Use
aria-label="Pagination"for screen readers. - Mark current page with
aria-current.
Example:
<nav aria-label="Pagination">
<ul>
<li><a href="?page=1">First</a></li>
<li><a href="?page=2" aria-current="page">2</a></li>
<li><a href="?page=3">Next</a></li>
</ul>
</nav>
How-To: Group Related Links in <nav> Using Semantic Structure
Steps:
- Use
<h2>or<h3>to label related groups. - Wrap content in appropriate semantic containers.
Example:
<nav role="navigation" aria-label="Quick links">
<h3>Useful Links</h3>
<ul>
<li><a href="/login">Login</a></li>
<li><a href="/register">Register</a></li>
</ul>
</nav>
How-To: Improve Focus Management in <nav> for Keyboard Users
Steps:
- Ensure all links are focusable.
- Apply visible focus indicators via CSS (
outline,:focus). - Test keyboard navigation.
Example:
nav a:focus {
outline: 2px solid #007BFF;
}
How-To: Use <nav> for Table of Contents in Long Articles
Steps:
- Create a list of headings or sections.
- Wrap with
<nav>and give it anaria-label. - Use
<ol>for ordered section links.
Example:
<nav aria-label="Article table of contents">
<ol>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
</nav>
How-To: Combine <nav> with Semantic Sections for Better SEO
Steps:
- Place
<nav>in logical sections like<header>,<aside>. - Make sure the structure reflects site hierarchy.
- Use clear
aria-labelsand meaningful link text.
Example:
<header>
<nav aria-label="Main menu">
<ul><li><a href="/">Home</a></li></ul>
</nav>
</header>
<aside>
<nav aria-label="Related posts">
<ul><li><a href="/post1">Post 1</a></li></ul>
</nav>
</aside>
How-To: Build a Sidebar Navigation with <nav>
Steps:
- Place navigation inside
<aside>or directly in body. - Use
<nav>for semantic clarity. - Add
aria-labelto identify the purpose.
Example:
<aside>
<nav aria-label="Site map">
<ul>
<li><a href="/sitemap">Full Sitemap</a></li>
<li><a href="/categories">Categories</a></li>
</ul>
</nav>
</aside>
How-To: Create a Multi-Level Dropdown Navigation Menu
Steps:
- Use nested
<ul>elements within<li>tags for sub-menus - Add
aria-haspopup="true"on parent items with dropdowns - Include
aria-expandedattributes to track open/closed states - Implement CSS for hover/focus effects and mobile responsiveness
Example:
<nav role="navigation" aria-label="Main navigation">
<ul>
<li class="dropdown">
<a href="/products" aria-haspopup="true" aria-expanded="false">Products</a>
<ul class="sub-menu">
<li><a href="/web-design">Web Design</a></li>
<li><a href="/mobile-apps">Mobile Apps</a></li>
<li class="dropdown">
<a href="/ecommerce" aria-haspopup="true" aria-expanded="false">E-commerce</a>
<ul class="sub-menu">
<li><a href="/shop">Shop</a></li>
<li><a href="/cart">Cart</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
How-To: Implement a Search-Focused Navigation Pattern
Steps:
- Place search-related links within
<nav>but outside primary navigation - Use
aria-labelto clarify the context (e.g., “Search results navigation”) - Include utility links like “Advanced Search”, “Filters” in separate nav blocks
- Ensure consistent styling and keyboard accessibility
Example:
<nav aria-label="Search navigation">
<ul>
<li><a href="/search">Quick Search</a></li>
<li><a href="/advanced-search">Advanced Search</a></li>
<li><a href="/filters">Refine Results</a></li>
</ul>
</nav>
<nav aria-label="Utility navigation">
<ul>
<li><a href="/login">Login</a></li>
<li><a href="/register">Register</a></li>
</ul>
</nav>
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!