Courses/HTML & CSS/HTML5 Semantic Architecture

    Advanced HTML5 Semantic Architecture

    Lesson 16 โ€ข Advanced Track

    What You'll Learn

    When to use header, main, article, section, aside, footer
    How semantic HTML improves SEO and accessibility
    Nesting rules: which elements belong inside which
    Landmark roles and how screen readers use them
    Building a full page layout with semantic elements
    Common anti-patterns: div soup and how to fix it

    ๐Ÿ’ก Think of It Like This

    Imagine a newspaper: It has a masthead (header), the main story (main), individual articles (article), a sidebar with related links (aside), and fine print at the bottom (footer). Semantic HTML mirrors this structure so browsers, search engines, and screen readers understand your page like a human would.

    ElementPurposeScreen Reader Role
    <header>Site or section heading areabanner
    <nav>Navigation linksnavigation
    <main>Primary page content (only one!)main
    <article>Self-contained content (blog post, news)article
    <section>Thematic grouping with a headingregion
    <aside>Sidebar, related content, adscomplementary
    <footer>Footer information, copyrightcontentinfo

    Semantic Page Structure

    Here's a complete blog-style page using every semantic element correctly.

    Full Semantic Page Layout

    A complete page using header, nav, main, article, aside, and footer

    Try it Yourself ยป
    Code Preview
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Semantic Page</title>
      <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { background: #0f172a; font-family: system-ui, sans-serif; color: #e5e7eb; }
    
        header {
          background: #1e293b;
          padding: 20px 30px;
          border-bottom: 2px solid #3b82f6;
        }
        header h1 { color: #3b82f6; font-size: 1.5rem; }
    
        nav {
          background: #1e293b;
          padding: 10px 30px;
          display: flex;
    
    ...

    Div Soup vs Semantic HTML

    See the difference between a page built with divs and one with semantic elements.

    Before & After: Div Soup Fix

    Transform meaningless divs into meaningful semantic elements

    Try it Yourself ยป
    Code Preview
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Div Soup Fix</title>
      <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { background: #0f172a; font-family: system-ui, sans-serif; color: #e5e7eb; padding: 20px; }
    
        .comparison { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
        .bad, .good { padding: 20px; border-radius: 8px; }
        .bad { background: #7f1d1d; border: 2px solid #ef4444; }
        .good { background: 
    ...

    โš ๏ธ Common Mistakes

    • Multiple <main> elements โ€” A page should have only ONE <main>. It represents the unique content of the page.
    • Using <section> without a heading โ€” Every <section> should have an h2โ€“h6 to describe it. If it doesn't need a heading, a <div> might be more appropriate.
    • Confusing <article> and <section> โ€” An article is self-contained (could be syndicated). A section is a thematic grouping within a page.
    • Wrapping everything in <article> โ€” Only use article for content that makes sense independently (blog post, news story, product card).

    ๐ŸŽ‰ Lesson Complete

    You now know how to architect pages with semantic HTML5 elements:

    • โœ… Use <header>, <main>, <footer> for page-level structure
    • โœ… Wrap standalone content in <article>, themed groups in <section>
    • โœ… Use <nav> for navigation and <aside> for sidebars
    • โœ… Semantic HTML improves SEO, accessibility, and code readability

    Sign up for free to track which lessons you've completed and get learning reminders.

    Previous

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy Policy โ€ข Terms of Service