Skip to main content

HTML <nav> Tag

The HTML <nav> tag defines navigation menus that guide users through their websites. It simplifies the process of creating multiple menus and menus containing links to external pages.

An example of how the <nav> tag can be used is by providing a dropdown menu containing links to different areas of a website. In the following code snippet, we will use the <nav> tag with an unordered list and some basic styling applied:

 <nav>
    <ul class="menu">
        <li><a href="#">Home</a></li>
        <li><a href="#">About Us</a></li>
        <li><a href="#">Contact Us</a></li>
    </ul>
</nav>

The above code creates a navigation menu showing links for Home, About Us, and Contact Us.

By adding further lists inside this navigation menu, more complex navigations like dropdown menus can be created easily using nested lists.

<nav>
   <ul class="menu">
      <li><a href="#">Home</a></li>
      <li>
         <a href="#">Products</a>
         <ul class="sub-menu">
            <li><a href="#">Product 1</a></li>
            <li><a href="#">Product 2</a></li>
            <li><a href="#">Product 3</a></li>
            <li><a href="#">Product 4</a></li>
            <li><a href="#">Product 5</a></li>
         </ul>
      </li>
      <li>
         <a href="#">Services</a>
         <ul class="sub-menu">
            <li><a href="#">Service 1</a></li>
            <li><a href="#">Service 2</a></li>
            <li><a href="#">Service 3</a></li>
            <li><a href="#">Service 4</a></li>
            <li><a href="#">Service 5</a></li>
         </ul>
      </li>
      <li><a href="#">About</a></li>
   </ul>
</nav >

This code will create a second-level dropdown menu accessible from the Products and Services link in the main navigation menu.

As an element of HTML5, the <nav> tag provides an easy way for developers to structure website content as well as increase page readability. The tag allows web developers to divide content into manageable sections and can also be used to include additional elements such as search boxes or buttons. This makes it easier for visitors to find what they are looking for on a website.

By using semantic elements such as these rather than non-semantic ones (such as div tags), search engines can better understand the structure and content of your pages, improving your SEO performance over time.