DEV Community

β†’ Ale Narvaja
β†’ Ale Narvaja

Posted on β€’ Edited on

When to use `main`, `section`, `article`, `header`, `footer`, and `aside` in HTML5

HTML5 introduced semantic elements that help structure web content more meaningfully β€” not only for developers but also for browsers and assistive technologies like screen readers.

If you're unsure when to use <main>, <section>, <article>, <header>, <footer>, or <aside>, this post is for you. Let's break down what they are, when to use them, and what not to do.


🧱 <main>

Defines the main content of the page β€” the part that makes it unique.

βœ… Use it for:

  • Blog posts, product listings, dashboards
  • Anything that's central to your page

❌ Don't use it for:

  • Headers, footers, nav menus, sidebars

⚠️ There should be only one <main> element per page.


πŸ“¦ <section>

Groups content that shares a common theme, ideally with a heading (<h1>–<h6>).

βœ… Use it for:

  • A "Latest Posts" section
  • A FAQ section
  • A page broken into logical parts

πŸ—£οΈ Tip: Use aria-label or include a heading for better accessibility.


πŸ“° <article>

A self-contained, reusable block of content β€” it should make sense on its own.

βœ… Use it for:

  • A blog post or news article
  • A user comment or review

❌ Don't use it to wrap unrelated things just because they’re grouped visually.


🎯 <header>

Introduces a section or the entire page. Can include:

  • Title
  • Logo
  • Navigation

βœ… Use it:

  • Once at the top of the page
  • Inside <section> or <article> as an intro

πŸ”š <footer>

Wraps up a section or page. Can include:

  • Author info
  • Related links
  • Copyright

βœ… Use it:

  • At the bottom of the page
  • Inside <article> to show metadata like date or tags

πŸ“Ž <aside>

Represents content that is related but not essential to the main content.

βœ… Use it for:

  • Sidebars
  • Related posts
  • Pull quotes, tips, or ads

🧠 Conclusion

Semantic HTML makes your code more accessible, maintainable, and understandable β€” not just for you, but for everyone who interacts with your site.

Thanks for taking the time to read, any feedback will be welcome :)

See you around.

Top comments (1)

Collapse
Β 
chrys profile image
Chrysanthus β€’

Good!