Select Page

The nav element in HTML5- how to use it.

The <nav> element is a new element introduced in HTLM5. It is used for navigational content. The <nav> element is used to link to other pages within the website or to other parts in the same page.


nanadwumor

May 27, 2023
navigation element

The nav element is a new element introduced in HTLM5. It is used for navigational content. The nav element is used to link to other pages within the website or to other parts in the same page. For instance, the use of table of contents to link to specific parts on the page.

The nav element is typically used for the main navigation on the website. This element normally wraps an unordered list element (ul) because it is common practice to use unordered list to code a navigation


Join other Subscribers on our YouTube channel and enjoy daily pogramming tutorials.


Syntax of <nav> element

Traditional way of marking up a navigation

Before the introduction of the nav element, the unordered list element (ul) was used to wrap the list item (li) element and for styling purpose, the ul element was usually given an id for reference. Web developers marked a navigation this way:

Output

Traditional way of marking up a navigation

Recommended


Modern way of marking up a navigation in HTML5

With the introduction of the nav element, not much has changed but the code is a bit different from the first. The nav element is used to wrap the list elements.

Output

Modern way of marking up a navigation in HTML5

Program to demonstrate the nav element inside a header element

The nav element may be put inside a header element. The header element contains introductory content that may comprise a navigational content. The nav element can also be placed in a footer too. It is a common practice to put a navigation menu in the footer of a page, the same navigation menu found on the main site.

Output

Program to demonstrate the nav element inside a header element

Program to demonstrate Multiple Navigation Groups in  a single nav element

Output

Program to demonstrate Multiple Navigation Groups in a single nav element

Recommmended Use of the nav element

You don’t have to put all your links on a page in a nav element. As a matter of fact, the HTML5 specification recommends that only the block of major navigation are put in the nav element. Other minor links to say, articles and other pages can be put in a sidebar

Global Attributes

The <nav> element supports the global attributes in HTML

Event Attributes

The <nav> element supports the event attributes in HTML

Default CSS Settings

The default CSS setting in most browsers is as below:


Share this article


You May Also Like…

Selecting a browser for HTML5 development

Selecting a browser for HTML5 development

Google's Chrome browser is simple to use and has the most up-to-date HTML5 features making it easier for developers....

Top 10 HTML5 formatting tags

Top 10 HTML5 formatting tags

HTML offers a range of elements for formatting text. HTML formatting tags include : <b> - Bold text...