Nav Tag in HTML

The <nav> tag in HTML represents a section of a page that contains major navigation links. It is used for menus, table of contents sections, breadcrumbs, pagination, category navigation, and other important link groups that help users move through a website or document. The tag is semantic, so it tells the browser and assistive technologies that the links inside are navigation, not just random links.

Not every group of links should be wrapped in <nav>. A sentence that links to one reference page does not need it. A footer with a few legal links may or may not need it depending on importance. The <nav> element is best for link groups that are important for movement around the site or page.

Basic Syntax of Nav Tag in HTML

The basic syntax uses opening and closing <nav> tags around navigation links. The links are often placed inside a list because a menu is naturally a list of choices, but a list is not strictly required by HTML. In most real projects, a list improves structure and styling control.

<nav aria-label="Main navigation">
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/html/">HTML</a></li>
    <li><a href="/css/">CSS</a></li>
    <li><a href="/javascript/">JavaScript</a></li>
  </ul>
</nav>

The aria-label in this example gives the navigation landmark a clear name. This becomes especially useful when a page has more than one navigation area, such as main navigation, breadcrumb navigation, and footer navigation.

When to Use Nav Tag

Use <nav> when the links form an important navigation block. The links should help users move across main site areas, related sections, pages in a sequence, or major parts of the current document. If removing the link group would make the page harder to navigate, it is probably a good candidate for <nav>.

  • Main website menu.
  • Sidebar category menu.
  • Table of contents for a long article or documentation page.
  • Breadcrumb navigation.
  • Pagination links for next and previous pages.
  • Footer navigation when the footer contains major site links.

When Not to Use Nav Tag

The <nav> tag should not be used just because links exist. Links appear naturally inside paragraphs, cards, callouts, articles, and footers. If a link is part of normal content, leave it inside that content. Overusing <nav> can make landmark navigation noisy for screen reader users.

SituationUse nav?
Main menu at the top of a websiteYes
Breadcrumb trailYes
Table of contents for a long pageYes
One link inside a paragraphNo
Author profile link below an articleUsually no
Small list of social linksUsually no, unless it is a major navigation block

Nav Inside Header

The most common place to see <nav> is inside a site <header>. This makes sense when the header introduces the website and the navigation provides the main paths through it. The two elements work together, but they carry different meanings.

<header class="site-header">
  <a href="/" class="logo">Nerds Do Stuff</a>

  <nav aria-label="Main navigation">
    <a href="/programming/">Programming</a>
    <a href="/electronics/">Electronics</a>
    <a href="/projects/">Projects</a>
  </nav>
</header>

In this structure, the header contains the brand and the nav. The <nav> specifically identifies the navigation links. CSS can then arrange the logo and menu horizontally, stack them on mobile, or turn the menu into a drawer without changing the semantic meaning.

Multiple Nav Elements on One Page

A page can have multiple <nav> elements. For example, a documentation page might have a main site menu, a sidebar table of contents, and next or previous article links. This is valid, but each important nav should be named clearly so users can distinguish them.

<nav aria-label="Main navigation">
  <a href="/">Home</a>
  <a href="/tutorials/">Tutorials</a>
</nav>

<nav aria-label="Article contents">
  <a href="#syntax">Syntax</a>
  <a href="#examples">Examples</a>
  <a href="#mistakes">Mistakes</a>
</nav>

<nav aria-label="Pagination">
  <a href="/html/header-tag-in-html/">Previous</a>
  <a href="/html/main-tag-in-html/">Next</a>
</nav>

Without accessible names, assistive technology may announce several landmarks simply as navigation. Names such as “Main navigation”, “Article contents”, and “Pagination” make the page easier to understand.

Nav Tag and Lists

Many developers place navigation links inside <ul> and <li> elements. This is a strong default choice because a navigation menu is usually a list of related choices. Lists also make it easy to add spacing, alignment, dropdown behavior, and responsive styling.

<nav aria-label="HTML lessons">
  <ul>
    <li><a href="/html/introduction/">HTML Introduction</a></li>
    <li><a href="/html/elements/">HTML Elements</a></li>
    <li><a href="/html/attributes/">HTML Attributes</a></li>
  </ul>
</nav>

There are cases where a simple set of links without a list is acceptable, especially for very small navigation groups. Still, lists are usually better for menus because they express that the links are a grouped set of choices.

A nav element should help users move, not merely decorate a group of links.

Nav Tag and Accessibility

The <nav> element creates a navigation landmark. Screen reader users can jump between landmarks instead of moving line by line through the page. This is very useful on large pages because it lets users quickly find the main menu, table of contents, or pagination.

When there is only one main nav, the meaning is usually obvious. When there are multiple nav elements, accessible names become important. You can use aria-label for a direct text label, or aria-labelledby when the nav has a visible heading that should act as the label.

<h2 id="lesson-menu">HTML Lesson Menu</h2>

<nav aria-labelledby="lesson-menu">
  <a href="/html/tables/">Tables in HTML</a>
  <a href="/html/forms/">Forms in HTML</a>
</nav>

This approach avoids duplicate invisible labels because the visible heading names the navigation region. It also makes the structure clearer for everyone reading the page.

Nav Tag in Responsive Menus

Responsive menus often use JavaScript to open and close navigation on small screens. The semantic structure should still remain correct. The menu button should be a real <button>, not a clickable <div>. The navigation links should remain inside <nav>. JavaScript should change visibility and state, not replace good HTML structure.

<button aria-expanded="false" aria-controls="main-menu">
  Menu
</button>

<nav id="main-menu" aria-label="Main navigation">
  <a href="/">Home</a>
  <a href="/html/">HTML</a>
  <a href="/css/">CSS</a>
</nav>

For a production menu, JavaScript should update aria-expanded when the menu opens or closes. Keyboard focus, visible focus styles, and escape behavior should also be handled carefully. The <nav> tag gives the menu a correct structural home, but it does not automatically solve every interaction detail.

Breadcrumb Navigation Example

Breadcrumbs show the path from a broad area to the current page. They are useful on tutorial websites, documentation sites, stores, and large blogs because they help users understand where they are. Breadcrumbs are a navigation pattern, so <nav> is appropriate when the breadcrumb trail is important to the page.

<nav aria-label="Breadcrumb">
  <ol>
    <li><a href="/">Home</a></li>
    <li><a href="/programming/">Programming</a></li>
    <li><a href="/html/">HTML</a></li>
    <li aria-current="page">Nav Tag in HTML</li>
  </ol>
</nav>

The final breadcrumb item often represents the current page. It does not need to be a link to itself. The aria-current="page" attribute makes the current location clearer for assistive technologies.

Pagination Navigation Example

Pagination is another good use of <nav>. It may appear in blog archives, product listings, search results, or tutorial tracks. If the links move the user between pages in a sequence, naming the navigation as pagination makes the purpose clear.

<nav aria-label="HTML tutorial pagination">
  <a href="/html/header-tag-in-html/" rel="prev">Previous</a>
  <a href="/html/main-tag-in-html/" rel="next">Next</a>
</nav>

The rel="prev" and rel="next" attributes are optional in many modern cases, but they still make the relationship understandable in the HTML. The link text should also be meaningful. If the visual design only shows arrows, add accessible text so users know where each link goes.

Testing navigation is simple but important. Try using only the keyboard, tab through the links, check that focus is visible, and confirm that collapsed mobile menus can be opened and closed without a mouse. Good navigation is not only correct markup; it must also be easy to operate on desktop, tablet, and phone screens. If users cannot confidently move around the site, the navigation still needs work before the page is ready. Clear navigation directly affects how long people stay and how easily they discover related pages during each visit too.


Common Mistakes with Nav Tag

  • Wrapping every small group of links in <nav>.
  • Using <nav> as a generic styling wrapper instead of a navigation landmark.
  • Creating multiple nav elements without accessible names.
  • Using JavaScript clickable containers instead of real links and buttons.
  • Hiding mobile navigation in a way that keyboard users cannot access.
  • Using vague link text such as “click here” inside navigation menus.
Can nav be inside header?

Yes. Main navigation is commonly placed inside the site header because it is part of the introductory area of the website.

Can a page have more than one nav tag?

Yes. Use multiple nav elements when the page has multiple important navigation regions, but label them clearly.

Should every link be inside nav?

No. Only major navigation groups should use nav. Normal links inside content should stay inside the content where they belong.

Best Practices

  • Use <nav> for important navigation groups.
  • Give multiple nav landmarks clear accessible names.
  • Use real <a> elements for navigation links.
  • Prefer lists for menu-style navigation.
  • Keep mobile menu behavior keyboard accessible.
  • Do not use <nav> only for visual styling.

Continue learning HTML in order
Follow the topic sequence with the previous and next lesson.