Loading Developer Playground

Loading ...

Skip to main content
ARIA ROLEโ€ขLandmark Roles

navigation

A collection of navigational elements (usually links) for navigating the document or related documents. Common uses include primary site navigation, footer menus, breadcrumbs, and table of contents.

Landmark RoleImplicit on <nav>WCAG 2.2
๐ŸŽฏ

Purpose

Identifies major navigation blocks that help users navigate the site or document

๐Ÿ“ฑ

HTML Equivalent

Automatically applied to <nav> elements

โ™ฟ

Screen Reader

Announced as "navigation" landmark for quick access to menus

๐Ÿ’กWhen to Use

1

Primary Site Navigation

Main menu with links to major sections of your website

2

Footer Navigation

Secondary navigation in the footer with utility links

3

Breadcrumb Navigation

Hierarchical trail showing the user's location in the site

4

Table of Contents

Links to major sections within a long document or article

๐Ÿ’ปCode Examples

Basic Navigation Role

Using the navigation role for primary site navigation

<!-- Using semantic HTML (Preferred) -->
<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/services">Services</a></li>
    <li><a href="/contact">Contact</a></li>
  </ul>
</nav>

<!-- Using role="navigation" explicitly -->
<div role="navigation">
  <a href="/">Home</a>
  <a href="/about">About</a>
  <a href="/contact">Contact</a>
</div>

Multiple Navigation Regions with Labels

Labeling multiple navigation regions to distinguish them

<!-- Main Navigation -->
<nav aria-label="Main navigation">
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/products">Products</a></li>
    <li><a href="/about">About</a></li>
  </ul>
</nav>

<!-- Footer Navigation -->
<nav aria-label="Footer navigation">
  <ul>
    <li><a href="/privacy">Privacy</a></li>
    <li><a href="/terms">Terms</a></li>
    <li><a href="/sitemap">Sitemap</a></li>
  </ul>
</nav>

<!-- Social Media Links -->
<nav aria-label="Social media">
  <a href="https://twitter.com" aria-label="Twitter">
    <svg><!-- icon --></svg>
  </a>
  <a href="https://facebook.com" aria-label="Facebook">
    <svg><!-- icon --></svg>
  </a>
</nav>

<!-- Breadcrumb Navigation -->
<nav aria-label="Breadcrumb">
  <ol>
    <li><a href="/">Home</a></li>
    <li><a href="/products">Products</a></li>
    <li aria-current="page">Product Name</li>
  </ol>
</nav>

React Navigation Component

Implementing accessible navigation in React

import { useState } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function MainNav() {
  const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
  const router = useRouter()

  const navLinks = [
    { href: '/', label: 'Home' },
    { href: '/about', label: 'About' },
    { href: '/services', label: 'Services' },
    { href: '/contact', label: 'Contact' },
  ]

  return (
    <nav aria-label="Main navigation">
      {/* Mobile Menu Toggle */}
      <button
        className="mobile-menu-toggle"
        aria-expanded={mobileMenuOpen}
        aria-controls="main-nav-list"
        onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
      >
        <span className="sr-only">
          {mobileMenuOpen ? 'Close' : 'Open'} menu
        </span>
        <svg><!-- Hamburger icon --></svg>
      </button>

      {/* Navigation Links */}
      <ul
        id="main-nav-list"
        className={mobileMenuOpen ? 'open' : ''}
      >
        {navLinks.map((link) => (
          <li key={link.href}>
            <Link
              href={link.href}
              aria-current={
                router.pathname === link.href ? 'page' : undefined
              }
            >
              {link.label}
            </Link>
          </li>
        ))}
      </ul>
    </nav>
  )
}

โญBest Practices

โœ“

Use Semantic HTML

Always use the <nav> element for navigation. It automatically has the navigation role.

๐Ÿท๏ธ

Label Multiple Navigations

Use aria-label or aria-labelledby when you have multiple navigation regions to distinguish them.

๐Ÿ“

Indicate Current Page

Use aria-current="page" on the link to the current page to help users know where they are.

๐Ÿ“ฑ

Mobile-Friendly

Ensure navigation works well on mobile with touch targets and hamburger menus if needed.

โŒจ๏ธ

Keyboard Accessible

All navigation links must be keyboard accessible with visible focus indicators.

๐Ÿ”„

Use for Navigation Only

Only use navigation role for major navigation blocks, not for every group of links.

โš ๏ธCommon Mistakes to Avoid

Unlabeled Multiple Navigations

โŒ Wrong

Having multiple navigation regions without labels

<nav>Main Menu</nav>
<nav>Footer Menu</nav> โŒ
โœ“ Correct

Add unique aria-label to each navigation region

<nav aria-label="Main navigation">
  Main Menu
</nav>
<nav aria-label="Footer navigation">
  Footer Menu
</nav> โœ“

Using for Non-Navigation

โŒ Wrong

Using navigation role for groups of links that aren't navigation

<nav>
  <h3>Related Articles</h3>
  <a href="/article1">Article 1</a>
  <a href="/article2">Article 2</a>
</nav> โŒ
โœ“ Correct

Only use for major navigation blocks

<aside>
  <h3>Related Articles</h3>
  <ul>
    <li><a href="/article1">Article 1</a></li>
    <li><a href="/article2">Article 2</a></li>
  </ul>
</aside> โœ“

๐Ÿ”—Related ARIA Attributes

aria-label

Provide a unique label for each navigation region

<nav aria-label="Main navigation">
Learn More โ†’

aria-current

Indicate the current page in navigation

<a href="/about" aria-current="page">About</a>
Learn More โ†’