Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › HTML Snippets › Reference › <aside> & <nav>

HTML Reference

<aside> & <nav> — Complementary and Navigation

Two landmark elements that guide users and screen readers through a page.

Last updated: October 2026

Definition: The <nav> element defines a section of navigation links. It is a landmark — screen readers can jump directly to it. The <aside> element is for content tangentially related to the main content — sidebars, related posts, or pull quotes. Both are semantic improvements over <div>.

🎬 Live Example

A typical blog layout — nav at the top, aside on the side, main content in the middle.

Main content
Article content...

💡 Each element is a landmark. Screen readers can jump directly to nav or aside.

📝

Basic Syntax

<!-- Navigation -->
<nav>
    <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/blog">Blog</a></li>
        <li><a href="/about">About</a></li>
    </ul>
</nav>

<!-- Aside (sidebar) -->
<aside>
    <h2>Related Posts</h2>
    <ul>
        <li><a href="/post-1">Post 1</a></li>
        <li><a href="/post-2">Post 2</a></li>
    </ul>
</aside>

⚙️ Attributes Reference

Both elements have no specific attributes. They use the standard global attributes:

Attribute Purpose
idUnique identifier for anchors and JavaScript.
classStyling classes.
aria-labelWhen multiple navs exist, label each one. Example: aria-label="Main navigation".
aria-labelledbyPoint to a heading ID to label the landmark.
1

nav — What Belongs Inside

Wrap navigation links in a <nav> and typically inside a <ul>.

<!-- Primary site navigation -->
<nav aria-label="Main">
    <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/courses">Courses</a></li>
        <li><a href="/blog">Blog</a></li>
        <li><a href="/contact">Contact</a></li>
    </ul>
</nav>

<!-- Breadcrumb navigation -->
<nav aria-label="Breadcrumb">
    <ol>
        <li><a href="/">Home</a></li>
        <li><a href="/courses">Courses</a></li>
        <li><a href="/courses/html">HTML</a></li>
    </ol>
</nav>

<!-- Table of contents -->
<nav aria-label="Table of contents">
    <ul>
        <li><a href="#intro">Introduction</a></li>
        <li><a href="#setup">Setup</a></li>
        <li><a href="#usage">Usage</a></li>
    </ul>
</nav>
2

What Does NOT Belong in nav

Not every group of links is navigation. Wrapping social media icons or related article links in <nav> is a common mistake.

Do NOT wrap in <nav>:

  • Social media icons in the footer
  • Related posts at the bottom of an article
  • Inline links inside a paragraph
  • Tag lists or category lists
  • Footer legal links (Privacy, Terms)

These are lists or groups of links, not navigation. Use <ul> or a <div> with a heading instead.

3

aside — Tangential Content

Use <aside> for content that is related to the main topic but not essential to it.

<!-- Sidebar with related links -->
<aside>
    <h2>Related Posts</h2>
    <ul>
        <li><a href="/html-semantic">Understanding Semantic HTML</a></li>
        <li><a href="/css-grid">CSS Grid Basics</a></li>
    </ul>
</aside>

<!-- Pull quote inside an article -->
<article>
    <p>The main article content...</p>
    <aside>
        <p>"Semantic HTML is not optional — it is the foundation of accessible web design."</p>
    </aside>
    <p>More content...</p>
</article>

<!-- Advertisement -->
<aside aria-label="Advertisement">
    <div class="ad-slot">...</div>
</aside>

<!-- Author bio at the end of a blog post -->
<article>
    <p>...article content...</p>
    <aside class="author-bio">
        <h3>About the Author</h3>
        <p>Jane Doe is a developer...</p>
    </aside>
</article>
4

Multiple navs on One Page

A page can have multiple <nav> elements. Label each one with aria-label so screen readers can distinguish them.

<body>
    <!-- 1. Primary site navigation -->
    <nav aria-label="Main">...</nav>

    <!-- 2. Breadcrumb -->
    <nav aria-label="Breadcrumb">...</nav>

    <main>
        <!-- 3. Table of contents in the sidebar -->
        <aside>
            <nav aria-label="Table of contents">...</nav>
        </aside>
    </main>

    <!-- 4. Footer navigation -->
    <footer>
        <nav aria-label="Footer">...</nav>
    </footer>
</body>
5

Accessible Navigation Menu

A complete accessible navigation pattern — the toggle uses ARIA attributes.

<nav aria-label="Main">
    <button
        aria-expanded="false"
        aria-controls="main-menu"
        class="menu-toggle">
        ☰ Menu
    </button>

    <ul id="main-menu">
        <li><a href="/">Home</a></li>
        <li><a href="/courses">Courses</a></li>
        <li><a href="/blog">Blog</a></li>
        <li><a href="/contact">Contact</a></li>
    </ul>
</nav>

<script>
    const toggle = document.querySelector(".menu-toggle");
    const menu = document.getElementById("main-menu");

    toggle.addEventListener("click", () => {
        const expanded = toggle.getAttribute("aria-expanded") === "true";
        toggle.setAttribute("aria-expanded", !expanded);
        menu.hidden = expanded;
    });
</script>

💡 Why aria-expanded matters: Screen readers announce the menu state ("collapsed" or "expanded"), so users know what the button will do.

🎯 nav & aside vs div

Content Element
Primary site navigation<nav>
Breadcrumb trail<nav>
Table of contents<nav>
Sidebar with related links<aside>
Pull quote<aside>
Advertisement<aside>
Author bio<aside>
Footer social icons<ul>
Tag list<ul>
Nothing fits<div>

⚠️ Common Mistakes

♿ Accessibility Notes

❓ Frequently Asked Questions

What is the HTML <nav> tag?

The <nav> element defines a section of navigation links. It is a landmark that screen readers can jump to. Use it for primary navigation, breadcrumbs, and table-of-contents — but not for every group of links on a page.

What is the HTML <aside> tag?

The <aside> element is for content tangentially related to the main content. Sidebars, pull quotes, related posts, and advertisements are common uses. Screen readers announce it as a complementary landmark.

How many nav elements can a page have?

There is no limit, but the practical number is 1 to 3. Common patterns: primary navigation (top), secondary navigation (sidebar), and a footer navigation. More than three becomes confusing.

Should I use nav for social media links?

Usually no. Social media icons in a footer are not primary navigation. Screen readers announce them as a navigation landmark, which is confusing. Use a plain list or a div with a heading instead.

What is the difference between nav and a list of links?

nav is a landmark that helps screen readers skip to navigation. A plain list is just a list. Use nav for the primary navigation and site-wide menus. Use a plain list for related links, tags, or inline link groups.

🎯 What's Next?

← All HTML Reference