👀 Live Preview
A horizontal main navigation menu:

The <nav> tag plays a pivotal role in creating navigational menus and links. This guide empowers you to build intuitive, semantic, and accessible navigation on your website.
Wrap navigation links inside <nav> opening and closing tags.
Identify major navigation blocks for SEO and screen readers.
Structure menus with lists and anchor links.
Build top-level site menus that users expect.
Organize legal and secondary links in the footer.
Use aria-label when multiple nav regions exist.
<nav> Tag?The <nav> element is a semantic HTML5 tag designed explicitly for defining navigation blocks on a web page. It encapsulates links, menus, and navigation-related content, helping structure the layout in a meaningful way.
Browsers and assistive technologies expose <nav> as a navigation landmark. Users can jump directly to nav regions with keyboard shortcuts, and search engines better understand your site structure.
Use nav for major navigation sections — not every group of links on a page. A sidebar of related article links or inline text links typically do not need a nav wrapper.
Enclose your navigation content between opening and closing <nav> tags:
<nav aria-label="Main navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/services">Services</a></li>
</ul>
</nav><nav> requires both opening and closing tags.<ul> of <li> items with <a> anchors.aria-label when the page has more than one nav element.nav inside another nav unnecessarily.| Pattern | Code Snippet | Notes |
|---|---|---|
| Basic nav | <nav><ul><li><a>...</a></li></ul></nav> | Standard menu |
| Named landmark | aria-label="Main" | Multiple nav regions |
| Styled nav | class="main-navigation" | CSS hook |
| Footer nav | <footer><nav>...</nav></footer> | Secondary links |
| vs div | <nav> semantic | Prefer over plain div |
| Attributes | Global only | class, id, aria-label |
The <nav> element has no unique attributes — global attributes and ARIA attributes apply:
class GlobalApply CSS classes for layout, colors, and responsive menu styles.
class="main-navigation"id GlobalUnique identifier for skip links or JavaScript menu toggles.
id="site-nav"aria-label A11yNames the navigation region when multiple nav elements exist on one page.
aria-label="Main navigation"style InlineInline styles work but external CSS is preferred for maintainability.
background: #1e293b<nav
class="main-navigation"
aria-label="Primary menu"
>
<!-- Your styled navigation content here -->
</nav>Styled navigation, main site menus, and footer link groups with copy-ready markup.
A horizontal main navigation menu:
Apply class and CSS to customize the appearance of your navigation block.
<nav class="main-navigation" aria-label="Primary menu">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>Use <nav> to structure the main navigation menu of a website (typically at the top or side) and to organize footer navigation links such as privacy policy and terms of service.
The primary site menu with Home, Products, and Contact links.
<nav aria-label="Main navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>Organize secondary links inside a <footer> with a nested <nav>.
<footer>
<nav aria-label="Footer links">
<ul>
<li><a href="/privacy">Privacy Policy</a></li>
<li><a href="/terms">Terms of Service</a></li>
</ul>
</nav>
</footer>Style navigation bars with flexbox, colors, and responsive breakpoints:
display: flex Horizontal menu:hover Link feedback:focus-visible Keyboard focus@media Mobile layout.main-navigation {
background: #1e293b;
padding: 0.75rem 1.25rem;
}
.main-navigation ul {
display: flex;
gap: 1rem;
list-style: none;
margin: 0;
padding: 0;
}
.main-navigation a {
color: #f8fafc;
text-decoration: none;
font-weight: 600;
}
.main-navigation a:hover {
color: #93c5fd;
}Styled navigation preview
Navigation must work for keyboard and screen reader users:
:focus-visible outlines on menu links.<a href="#main">Skip to content</a> before the nav for keyboard users.Place the site menu inside <nav> with a <ul> list of anchor links.
Assistive technology registers nav as a navigation region users can jump to.
Flexbox, colors, and media queries shape horizontal or mobile-friendly layouts.
Users and search engines understand where major navigation lives on every page.
The <nav> element is an HTML5 semantic tag with full support in all modern browsers and Internet Explorer 9+.
From IE9 to the latest mobile browsers — nav renders as a block-level container in every environment.
Bottom line: Use <nav> confidently for semantic navigation landmarks in every production environment today.
Mastering the <nav> tag is essential for crafting effective and user-friendly navigation on your website. By incorporating this semantic element, you enhance both the structure of your HTML and the overall user experience.
Combine nav with ul, li, and a for well-structured menus, add aria-label when needed, and apply responsive CSS so navigation works on every device.
nav for major navigation blocksul and li for structurearia-label for multiple nav regionsnavdiv when nav is appropriate<nav>Bookmark these before you build site navigation.
<nav> marks major link sections.
Standard accessible menu structure.
PatternTop or side primary navigation.
Use caseSecondary nav inside footer.
Use caseName multiple nav regions.
A11yHTML5 — IE9+ and all modern browsers.
Compatibilitynav for major navigation sections, not minor inline or sidebar link lists.nav is semantic navigation. div has no meaning. Prefer nav for menus.nav elements exist on one page to distinguish main menu from footer links.Practice main and footer menus in the Try It editor.
6 people found this page helpful