The nav tag in HTML5
- 24-07-2022
- Trung Minh
- 0 Comments
In this article we will learn how to use the nav tag in HTML5, which is a tag used to declare navigation link locations, usually menus or sidebar categories lists.
Note that not all navigation links are placed in the nav tag. The nav tag should only be used to wrap main navigation blocks such as page menus.
1. What is the nav tag in HTML?
In HTML, the nav tag is used to wrap the main navigation and link-related locations for the web page. Usually it will be the main menu, sub-menu, sidebar category list…
Nav is an acronym for navigation, its syntax is as follows:
<nav>...</nav>
2. How to use the nav tag in HTML
As I said above, we should only use the nav tag for the main navigation links for the website.
In the past, when creating menus, we often used ul tags and a tags as follows.
<div id="menu"> <ul> <li><a href="#">Home</a></li> ... </ul> </div>
But if we use the nav tag, we will change the structure to:
nav> <ul> <li><a href="#">Home</a></li> ... </ul> </nav>
Also nothing special, just change the outer div
tag to a nav
tag.
For example , use the nav tag to group a page's navigation menus.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <main> <h2>Khóa học có tại web888.vn</h2> <div> <nav> <a href="#">HTML</a> | <a href="#">CSS</a> | <a href="#">JavaScript</a> | <a href="#">jQuery</a> </nav> </div> </main> </body> </html>
So I have finished the tutorial on how to use the nav tag in HTML. This card is also simple, so I don't have too many examples for the lesson, hope you understand.