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)
Good!