|

HTML 17 💻 Layout elements

Semantic elements are HTML elements that carry meaning about the content they contain. They describe the purpose of the content rather than just its appearance, making web pages more accessible, SEO-friendly, and maintainable.


Semantic vs. Non-Semantic Elements

TypeDescriptionExamples
SemanticElements with meaning that describe content structure<header>, <nav>, <main>, <article>, <section>, <aside>, <footer>, <details>
Non-SemanticGeneric containers with no meaning<div>, <span>

Why Use Semantic Elements?

BenefitDescription
AccessibilityScreen readers understand page structure better
SEOSearch engines prioritize content based on context
MaintainabilityCode is easier to read and understand
InteroperabilityBrowsers and tools interpret content correctly

Common Layout/Semantic Elements

ElementPurposeExample
<header>Introductory content or navigationPage header, article header
<nav>Navigation linksMain menu, breadcrumbs
<main>Main content of the pagePrimary content area
<section>Thematic grouping of contentChapters, sections
<article>Self-contained contentBlog posts, news articles
<aside>Side content (tangentially related)Sidebars, pull quotes
<footer>Footer informationCopyright, contact info
<details>Expandable contentFAQ sections
<summary>Heading for <details>Clickable summary

Detailed Explanation

1. Header <header>

The <header> element represents introductory content or a group of navigational aids.

<header>
    <h1>My Website</h1>
    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</header>

Common Uses:

  • Page/section titles
  • Logos and branding
  • Navigation menus
  • Search forms

2. Navigation <nav>

The <nav> element defines a section containing navigation links.

<nav>
    <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
        <li><a href="/services">Services</a></li>
        <li><a href="/contact">Contact</a></li>
    </ul>
</nav>

Common Uses:

  • Primary navigation menus
  • Breadcrumb navigation
  • Table of contents
  • Pagination links

3. Main <main>

The <main> element represents the dominant content of the document. There should be only one per page.

<main>
    <h1>Welcome to My Site</h1>
    <p>This is the main content of the page.</p>
</main>

Important:

  • Only one <main> per page
  • Should not be nested inside <header>, <footer>, <article>, or <aside>

4. Section <section>

The <section> element represents a thematic grouping of content, typically with a heading.

<section>
    <h2>Our Services</h2>
    <p>We offer a wide range of services to meet your needs.</p>
    <ul>
        <li>Web Design</li>
        <li>Web Development</li>
        <li>SEO Optimization</li>
    </ul>
</section>

<section>
    <h2>Testimonials</h2>
    <blockquote>Great service! - John Doe</blockquote>
</section>

When to Use:

  • Grouping related content
  • Chapters or parts of a document
  • Different sections of a homepage

5. Article <article>

The <article> element represents self-contained, independent content that could be distributed or reused.

<article>
    <header>
        <h2>My Latest Blog Post</h2>
        <p>Published on <time datetime="2024-01-15">January 15, 2024</time></p>
    </header>
    <p>This is my latest blog post, featuring some great tips and tricks for web development.</p>
    <footer>
        <p>Written by John Doe</p>
    </footer>
</article>

When to Use:

  • Blog posts
  • News articles
  • Product cards
  • Forum posts
  • User comments

6. Aside <aside>

The <aside> element represents content that is tangentially related to the main content.

<aside>
    <h3>Related Links</h3>
    <ul>
        <li><a href="#">Web Development Tutorials</a></li>
        <li><a href="#">Design Inspiration</a></li>
        <li><a href="#">Best Practices</a></li>
    </ul>
</aside>

When to Use:

  • Sidebars
  • Pull quotes
  • Related content
  • Advertisements
  • Author bio

7. Footer <footer>

The <footer> element represents footer information for its nearest ancestor sectioning content.

<footer>
    <p>&copy; 2024 My Website. All rights reserved.</p>
    <nav>
        <a href="/privacy">Privacy Policy</a> |
        <a href="/terms">Terms of Service</a>
    </nav>
</footer>

Common Uses:

  • Copyright notices
  • Contact information
  • Site maps
  • Legal disclaimers
  • Social media links

8. Details & Summary

The <details> and <summary> elements create an expandable/collapsible content section.

<details>
    <summary>FAQ</summary>
    <p>Here are some frequently asked questions:</p>
    <ul>
        <li><strong>How do I get started?</strong> - Start by learning HTML basics.</li>
        <li><strong>What are the best tools?</strong> - VS Code, Chrome DevTools, and Git.</li>
        <li><strong>Is this free?</strong> - Yes, all resources are free.</li>
    </ul>
</details>

Key Points:

  • <summary> provides the visible heading
  • Clicking the summary toggles the content
  • Can be used for FAQs, collapsible menus, and expandable content
  • The open attribute can make it expanded by default

Complete Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Semantic Layout Elements</title>
    <style>
        /* ====== Global Styles ====== */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1.6;
            color: #333;
            background: #f4f4f4;
            padding: 20px;
        }

        /* ====== Layout Styles ====== */
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
        }

        /* ====== Header ====== */
        header {
            background: linear-gradient(135deg, #007bff, #0056b3);
            color: white;
            padding: 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }

        header h1 {
            font-size: 2em;
        }

        nav ul {
            display: flex;
            list-style: none;
            gap: 20px;
        }

        nav a {
            color: white;
            text-decoration: none;
            padding: 5px 15px;
            border-radius: 5px;
            transition: background 0.3s;
        }

        nav a:hover {
            background: rgba(255,255,255,0.2);
        }

        /* ====== Main Content ====== */
        .content-wrapper {
            display: flex;
            gap: 30px;
            padding: 30px;
            flex-wrap: wrap;
        }

        /* ====== Main Area ====== */
        main {
            flex: 2;
            min-width: 300px;
        }

        main h2 {
            color: #007bff;
            margin-bottom: 10px;
        }

        .post-meta {
            color: #6c757d;
            font-size: 0.9em;
            margin-bottom: 15px;
        }

        /* ====== Article ====== */
        article {
            background: #f8f9fa;
            padding: 25px;
            border-radius: 8px;
            margin-bottom: 20px;
            border-left: 4px solid #007bff;
        }

        article h3 {
            color: #333;
            margin-bottom: 5px;
        }

        /* ====== Section ====== */
        section {
            margin: 20px 0;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 8px;
        }

        section h2 {
            color: #28a745;
        }

        /* ====== Aside ====== */
        aside {
            flex: 1;
            min-width: 250px;
            background: #f8f9fa;
            padding: 25px;
            border-radius: 8px;
            height: fit-content;
            border-left: 4px solid #ffc107;
        }

        aside h3 {
            color: #ffc107;
            margin-bottom: 10px;
        }

        aside ul {
            list-style: none;
            padding: 0;
        }

        aside li {
            padding: 5px 0;
        }

        aside a {
            color: #007bff;
            text-decoration: none;
        }

        aside a:hover {
            text-decoration: underline;
        }

        /* ====== Details/Summary ====== */
        details {
            margin: 20px 30px 30px;
            padding: 15px 20px;
            background: #f8f9fa;
            border-radius: 8px;
            border: 1px solid #ddd;
        }

        summary {
            font-weight: bold;
            font-size: 1.1em;
            cursor: pointer;
            padding: 10px 0;
            color: #007bff;
        }

        summary:hover {
            color: #0056b3;
        }

        details ul {
            padding-left: 20px;
            margin: 10px 0;
        }

        details li {
            padding: 5px 0;
        }

        /* ====== Footer ====== */
        .footer-main {
            background: #343a40;
            color: white;
            padding: 20px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }

        .footer-main a {
            color: #ffc107;
            text-decoration: none;
        }

        .footer-main a:hover {
            text-decoration: underline;
        }

        .article-footer {
            padding: 10px 0;
            font-size: 0.9em;
            color: #6c757d;
        }

        /* ====== Responsive ====== */
        @media (max-width: 768px) {
            header {
                flex-direction: column;
                text-align: center;
            }

            nav ul {
                flex-direction: column;
                gap: 10px;
                margin-top: 15px;
            }

            .content-wrapper {
                flex-direction: column;
            }

            .footer-main {
                flex-direction: column;
                text-align: center;
                gap: 10px;
            }
        }
    </style>
</head>
<body>

    <div class="container">

        <!-- ====== HEADER ====== -->
        <header>
            <h1>🏠 My Website</h1>
            <nav>
                <ul>
                    <li><a href="#">Home</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Blog</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>
            </nav>
        </header>

        <!-- ====== CONTENT WRAPPER ====== -->
        <div class="content-wrapper">

            <!-- ====== MAIN ====== -->
            <main>

                <h2>Welcome to My Website</h2>
                <p>This page demonstrates the use of semantic HTML5 layout elements. Each element has a specific meaning and purpose.</p>

                <!-- ====== SECTION ====== -->
                <section>
                    <h2>💡 Latest Articles</h2>

                    <!-- ====== ARTICLE 1 ====== -->
                    <article>
                        <header style="background: none; padding: 0; color: #333;">
                            <h3>My Latest Blog Post</h3>
                            <p class="post-meta">Published on <time datetime="2024-01-15">January 15, 2024</time> by John Doe</p>
                        </header>
                        <p>This is my latest blog post, featuring some great tips and tricks for web development. Semantic HTML is essential for modern web development!</p>
                        <footer class="article-footer">
                            📂 Category: Web Development | 💬 12 Comments
                        </footer>
                    </article>

                    <!-- ====== ARTICLE 2 ====== -->
                    <article>
                        <header style="background: none; padding: 0; color: #333;">
                            <h3>Understanding CSS Flexbox</h3>
                            <p class="post-meta">Published on <time datetime="2024-01-10">January 10, 2024</time> by Jane Smith</p>
                        </header>
                        <p>Flexbox is a powerful layout model in CSS. It makes it easy to create responsive designs without using floats or positioning.</p>
                        <footer class="article-footer">
                            📂 Category: CSS | 💬 8 Comments
                        </footer>
                    </article>
                </section>

            </main>

            <!-- ====== ASIDE ====== -->
            <aside>
                <h3>🔗 Related Links</h3>
                <ul>
                    <li><a href="#">Web Development Tutorials</a></li>
                    <li><a href="#">Design Inspiration</a></li>
                    <li><a href="#">Best Practices for SEO</a></li>
                    <li><a href="#">Accessibility Guidelines</a></li>
                    <li><a href="#">HTML5 Cheat Sheet</a></li>
                </ul>

                <hr style="margin: 20px 0; border-color: #ddd;">

                <h3>📊 Quick Stats</h3>
                <ul>
                    <li>📝 45 Blog Posts</li>
                    <li>👥 1,200 Subscribers</li>
                    <li>⭐ 4.8/5 Rating</li>
                </ul>
            </aside>

        </div>

        <!-- ====== DETAILS / SUMMARY ====== -->
        <details>
            <summary>❓ Frequently Asked Questions</summary>
            <p>Here are some frequently asked questions:</p>
            <ul>
                <li><strong>How do I get started?</strong> - Start by learning HTML basics, then CSS, then JavaScript.</li>
                <li><strong>What are the best tools?</strong> - VS Code for coding, Chrome DevTools for debugging, and Git for version control.</li>
                <li><strong>Is this content free?</strong> - Yes, all content on this site is completely free.</li>
                <li><strong>How often do you post?</strong> - We post new articles every Tuesday and Thursday.</li>
            </ul>
        </details>

        <!-- ====== FOOTER ====== -->
        <footer class="footer-main">
            <p>&copy; 2024 My Website. All rights reserved.</p>
            <nav>
                <a href="#">Privacy Policy</a> |
                <a href="#">Terms of Service</a> |
                <a href="#">Contact Us</a>
            </nav>
        </footer>

    </div>

</body>
</html>

Semantic Elements Reference Table

ElementDescriptionTypical Uses
<header>Introductory contentPage headers, article headers
<nav>Navigation linksMenus, breadcrumbs, pagination
<main>Primary contentMain content area (only one per page)
<section>Thematic groupingChapters, parts, categories
<article>Self-contained contentBlog posts, news, comments
<aside>Supplementary contentSidebars, pull quotes, ads
<footer>Footer informationCopyright, links, contact info
<details>Expandable contentFAQs, collapsible sections
<summary>Heading for <details>Toggle labels

Best Practices

Do This:

<!-- Use header for introductory content -->
<header>
    <h1>Blog Title</h1>
</header>

<!-- Use nav for navigation -->
<nav>
    <ul>
        <li><a href="/">Home</a></li>
    </ul>
</nav>

<!-- Use main for primary content (only once) -->
<main>
    <article>
        <h2>Article Title</h2>
        <p>Content...</p>
    </article>
</main>

<!-- Use aside for related content -->
<aside>
    <h3>Related</h3>
    <ul>
        <li><a href="#">Link</a></li>
    </ul>
</aside>

<!-- Use footer at the bottom -->
<footer>
    <p>&copy; 2024 My Site</p>
</footer>

Don’t Do This:

<!-- Don't use div when semantic elements exist -->
<div class="header">Header</div>

<!-- Don't use multiple main elements -->
<main>Content 1</main>
<main>Content 2</main>  <!-- Invalid -->

<!-- Don't put everything in one section -->
<section>
    <h1>Title</h1>
    <p>Content</p>
    <nav>Navigation</nav>  <!-- This belongs outside -->
    <footer>Footer</footer>  <!-- This belongs outside -->
</section>

<!-- Don't use aside for unrelated content -->
<aside>
    <h2>Main Article</h2>  <!-- This should be in main -->
    <p>...</p>
</aside>

When to Use Semantic Elements

ScenarioRecommended Element
Page header with logo and navigation<header>
Main navigation menu<nav>
Primary page content<main>
Group of related articles<section>
Individual blog post<article>
Sidebar with related links<aside>
Page footer with copyright<footer>
Expandable FAQ section<details>

Pro Tip: Using semantic elements is not just about accessibility — it also improves your website’s SEO. Search engines give more weight to content inside semantic elements like <article> and <main>. Always prefer semantic elements over <div> and <span> when the content has meaning!


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!