<nav>

Term side of the Card.
Topic: Semantics
Unit title: <nav>
Categories: Tag
Explanation side of the Card

Explanation: The element that defines a block of navigation links, such as a menu or table of contents. It helps users navigate through different sections of the webpage or website.

Browser compatibility:
  • The chrome browser supports this feature starting from version 5.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 4.
  • The safari browser supports this feature starting from version 5.
Availability: 

Example

Wronghtml
<nav>
  <a class="active" href="/">Home</a>
  <a href="/docs">Docs</a>
</nav>
Righthtml
<nav aria-label="Main">
  <a aria-current="page" href="/">Home</a>
  <a href="/docs">Docs</a>
</nav>

The label names the landmark, and aria-current tells screen readers which page is active.

Common mistakes

  • Wrapping every group of links, like footer legal links, in <nav>.
  • Having two unlabeled <nav> elements that screen readers cannot tell apart.

Key points

  • Each <nav> on a page has a distinct aria-label, like 'Main' or 'Breadcrumb'.
  • The link to the current page has aria-current="page".
  • Navigation items are real <a href> links, often inside a <ul>.

Interview questions

Should links inside <nav> be in a list?

A <ul> is common and lets screen readers announce the number of links, but it is not required.

Can I have more than one <nav> on a page?

Yes. Give each one a unique aria-label so users can tell them apart.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy