Course contentsShow
← Web Development
Lesson 59 of 2,9822. HTML FundamentalsFree lesson

Nesting Semantic Elements

Understanding valid nesting patterns for semantic elements and creating proper document structures.

Nesting Semantic Elements

You'll learn: How to combine semantic elements inside each other to create well-structured, meaningful HTML documents.

The Big Idea

Just like Russian nesting dolls fit inside one another, semantic HTML elements can be placed inside other semantic elements. Understanding which elements can go inside others—and where—is crucial for creating valid, logical document structures. Not all combinations make sense: you wouldn't put a <header> inside an <address>, just like you wouldn't store your garage inside your mailbox!

Valid Nesting Patterns

Some common, logical patterns:

  • <article> inside <main>: Your main content area can contain multiple articles
  • <section> inside <article>: Break an article into thematic sections
  • <header> and <footer> inside <article>: Articles can have their own headers and footers
  • <figure> inside <article> or <section>: Place captioned images where they belong contextually
  • <aside> inside <main>: Related sidebars within your main content

What NOT to Do

  • Don't nest <main> inside <main> (there's only one main content area per page)
  • Don't put <header>, <footer>, or <main> inside <address> (addresses are for contact info, not structure)
  • Avoid nesting <header> or <footer> inside themselves

Think in Layers

Imagine building with boxes: large containers (<main>) hold medium containers (<article>), which hold smaller containers (<section>, <header>), which hold content. Each layer adds meaning and organization.

Key Takeaway: Semantic elements nest logically based on their meaning—larger structural elements contain smaller ones, creating a hierarchy that makes sense both to browsers and to developers reading your code.