<nav>: The Navigation Section element - HTML: HyperText Markup Language | MDN (2024)

The <nav> HTML element represents a section of a page whose purpose is to provide navigation links, either within the current document or to other documents. Common examples of navigation sections are menus, tables of contents, and indexes.

Try it

Content categories Flow content, sectioning content, palpable content.
Permitted content Flow content.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts flow content.
Implicit ARIA role navigation
Permitted ARIA roles No role permitted
DOM interface HTMLElement

Attributes

This element only includes the global attributes.

Usage notes

  • It's not necessary for all links to be contained in a <nav> element. <nav> is intended only for a major block of navigation links; typically the <footer> element often has a list of links that don't need to be in a <nav> element.
  • A document may have several <nav> elements, for example, one for site navigation and one for intra-page navigation. aria-labelledby can be used in such case to promote accessibility, see example.
  • User agents, such as screen readers targeting disabled users, can use this element to determine whether to omit the initial rendering of navigation-only content.

Examples

In this example, a <nav> block is used to contain an unordered list (<ul>) of links. With appropriate CSS, this can be presented as a sidebar, navigation bar, or drop-down menu.

html

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

The semantics of the nav element is that of providing links. However a nav element doesn't have to contain a list, it can contain other kinds of content as well. In this navigation block, links are provided in prose:

html

<nav> <h2>Navigation</h2> <p> You are on my home page. To the north lies <a href="/blog">my blog</a>, from whence the sounds of battle can be heard. To the east you can see a large mountain, upon which many <a href="/school">school papers</a> are littered. Far up this mountain you can spy a little figure who appears to be me, desperately scribbling a <a href="/school/thesis">thesis</a>. </p> <p> To the west are several exits. One fun-looking exit is labeled <a href="https://games.example.com/">"games"</a>. Another more boring-looking exit is labeled <a href="https://isp.example.net/">ISP™</a>. </p> <p> To the south lies a dark and dank <a href="/about">contacts page</a>. Cobwebs cover its disused entrance, and at one point you see a rat run quickly out of the page. </p></nav>

Result

Specifications

Specification
HTML Standard
# the-nav-element

Browser compatibility

BCD tables only load in the browser

See also

As a seasoned web development expert with years of practical experience, I can confidently delve into the intricacies of the HTML <nav> element and its associated concepts. My extensive hands-on experience in building and maintaining web applications has given me a deep understanding of HTML semantics and best practices. Let's break down the information provided in the article:

1. The <nav> HTML Element:

The <nav> element is a fundamental part of HTML5, representing a section of a webpage designed for navigation links. These links can lead either within the current document or to other documents. It is commonly used for menus, tables of contents, and indexes.

2. Purpose and Usage:

3. Content Categories:

The <nav> element supports the following content categories:

  • Flow Content: Content that can be placed within the normal flow of the document.

  • Sectioning Content: Content that defines the structure of the document.

  • Palpable Content: Content that is considered meaningful to users when CSS is disabled.

4. Tag Omission:

Both the starting and ending tags of the <nav> element are mandatory. No tag omission is allowed.

5. Permitted Parents:

The <nav> element can be a child of any element that accepts flow content.

6. ARIA (Accessible Rich Internet Applications):

  • Implicit ARIA Role: The implicit ARIA role of the <nav> element is set to "navigation."

  • Permitted ARIA Roles: No other role is permitted for the <nav> element.

7. DOM Interface:

The <nav> element corresponds to the HTMLElement in the Document Object Model (DOM).

8. Attributes:

The <nav> element includes only the global attributes.

9. Usage Notes:

  • It is not mandatory for all links to be contained within a <nav> element.

  • <nav> is intended for a major block of navigation links.

  • A document can have several <nav> elements, each serving a different purpose (e.g., site navigation, intra-page navigation).

  • aria-labelledby attribute can be used for accessibility.

10. Examples:

Two examples are provided to illustrate the use of <nav>. One uses an unordered list for navigation links, and the other includes links embedded in prose.

11. Result and Specifications:

Information about the specifications for the <nav> element and browser compatibility is included.

12. See Also:

Other section-related elements and ARIA-related information are provided for further reference.

In summary, the <nav> element is a crucial tool for creating well-structured and accessible navigation on web pages, and its flexible usage allows for various design implementations.

<nav>: The Navigation Section element - HTML: HyperText Markup Language | MDN (2024)

FAQs

<nav>: The Navigation Section element - HTML: HyperText Markup Language | MDN? ›

<nav>: The Navigation Section element

What is the nav element in HTML? ›

The nav element represents a section of a page that links to other pages or to parts within the page: a section with navigation links. Not all groups of links on a page need to be in a nav element — the element is primarily intended for sections that consist of major navigation blocks.

What is a nav bar in HTML? ›

A navigation bar (also called a Navbar) is a user interface element within a webpage that contains links to other sections of the website. In most cases, the navigation bar is part of the main website template, which means it is displayed on most, if not all, of the pages within the website.

What is the difference between NAV and navigation in HTML? ›

A "navbar" is an area on a page that contains navigation components (links, buttons, etc) for getting to other pages of the website. A "nav" is an HTML element that is normally used to enclose other elements related to navigation.

How do you add a navigation system in HTML? ›

Steps to Create a Navigation Bar: In-Depth
  1. Open a Text Editor. Open a new text editor or your pre-existing CSS file in an app folder. ...
  2. Create a <nav> tag. Insert a <nav> tag inside the <body> tag of your CSS file. ...
  3. Define the <ul> tag. ...
  4. Define the <style> tag. ...
  5. Change the design. ...
  6. Close the tags.
Apr 9, 2022

Why should I use NAV tag in HTML? ›

It plays a crucial role in web development. The <nav> tag gives semantic meaning to the enclosed content, indicating that it's a navigation section. It can improve a site's SEO because search engines prefer well-structured and semantically meaningful content.

When should I use NAV in HTML? ›

The <nav> element is intended only for major blocks of navigation links. Browsers, such as screen readers for disabled users, can use this element to determine whether to omit the initial rendering of this content.

What is the difference between NAV and menu? ›

The “<nav>” tag creates navigation block which provides link for contents either on the same document/page or any other document/page. The “<menu>” tag creates a list or menu of commands which can be utilized by the users.

What is the best way to create a navbar? ›

The easiest way to create a navigation bar is to use an unordered list and style it with CSS. Navigation Bars are mostly made up of <ul> lists that are horizontally arranged and styled.

What is a navigation link? ›

A navigation link is a type of link that helps website users get oriented and access different parts of a site.

Should I use header or NAV HTML? ›

The <header> tag is generally used for heading purposes, you may see the use of these header tags <h1> to <h6>. The <nav> tag is used inside the <header> tag. This may happen if <nav> is very small and if the content of <nav> tag is used to identify the different web content.

How many NAV elements are there in HTML? ›

You can have multiple nav lists in the same page or document, but you don't have to use the nav element for all of the links in your document.

What is NAV and Div tag in HTML? ›

Nav tag is semantic element. Means it should be used for Navigation. Div tag is not semantic element. But it can be used to create Containers and hold other elements to make layout.

What is the difference between NAV and div? ›

In HTML, the <nav> element is a semantic HTML5 element specifically designed to represent navigation links on a page. While you can use a <div> to create a similar structure, using <nav> provides better clarity and semantic meaning to your code.

What does CSS stand for? ›

CSS is the acronym of “Cascading Style Sheets”. CSS is a computer language for laying out and structuring web pages (HTML or XML). This language contains coding elements and is composed of these “cascading style sheets” which are equally called CSS files (. css).

What is JavaScript language? ›

JavaScript is a scripting or programming language that allows you to implement complex features on web pages — every time a web page does more than just sit there and display static information for you to look at — displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, ...

What is NAV and header in HTML? ›

Semantic Elements in HTML
TagDescription
<header>Specifies a header for a document or section
<main>Specifies the main content of a document
<mark>Defines marked/highlighted text
<nav>Defines navigation links
9 more rows

Is NAV a container tag? ›

The <nav> tag creates a container for navigation elements. It can hold navigation menus, quicklinks, table of contents, etc.

Top Articles
Latest Posts
Article information

Author: Aracelis Kilback

Last Updated:

Views: 5680

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Aracelis Kilback

Birthday: 1994-11-22

Address: Apt. 895 30151 Green Plain, Lake Mariela, RI 98141

Phone: +5992291857476

Job: Legal Officer

Hobby: LARPing, role-playing games, Slacklining, Reading, Inline skating, Brazilian jiu-jitsu, Dance

Introduction: My name is Aracelis Kilback, I am a nice, gentle, agreeable, joyous, attractive, combative, gifted person who loves writing and wants to share my knowledge and understanding with you.