<nav> Tag in HTML
The <nav> tag is used to define navigation links in a web page. It groups together links that help the user navigate through the website. It is typically used for main menus or sections with significant navigation items. The <nav>
element is placed inside the <body>
of the HTML document.
Key Points on <nav> Tag:
- Used to create a block of navigation links.
- Helps screen readers and other accessibility tools understand navigation areas.
- Enhances the overall user experience by providing organized and clear navigation.
- Typically used for top-level or main menus, but can also be used for smaller navigational sections like footers or sidebars.
Syntax of <nav> Tag:
Syntax Example
Examples of <nav> Tag Usage:
1. Simple Navigation Menu
Code Example
2. Navigation with a List of Links
Code Example
Attributes of <nav> Tag:
- None: The
<nav>
tag itself does not have specific attributes. - Role: In some cases, the
role="navigation"
attribute can be used for accessibility purposes, but it is not necessary when the<nav>
tag is used.
The <nav>
tag is an essential part of web design and accessibility. It helps organize links that lead users to other parts of the website, making navigation easier and more intuitive.