← Back to HTML & CSS, page 8

html-css-0149 · Easy fresher

When do you use article, section, aside and div?

article is self-contained content, section is a thematic group that should have a heading, aside is related but removable content, and div has no meaning. A section with an accessible name is exposed as a region, and aside as complementary.

Full answer

These elements all group content, but they carry different meaning.

  • article is a self-contained piece that makes sense on its own and could be shared or reused: a blog post, a news story, a product card in a list, a comment. A test is whether it would still make sense in a feed or an email.
  • section is a thematic group of content, usually with a heading. It is part of a larger whole, such as "Pricing" and "Reviews" on a page. A section without a heading or a name is just a div with extra words. With an accessible name (for example aria-labelledby pointing to its heading), it becomes a region landmark for screen reader users.
  • aside is content that is related to the main content but could be removed without breaking it: a sidebar, a pull quote, a box of related links. It is a complementary landmark.
  • div has no meaning. Use it when you need a box for styling or scripting and no other element fits.

Other points:

  • Do not use section just to apply CSS. Use div for that.
  • Each article and section should usually have a heading, so a user who moves by headings can understand the page.
  • Pick the element by meaning, then style it. The correct element can give you landmarks for free, and too many unnamed landmarks make navigation noisy.
  • Use header, footer, nav and main for page-level parts. header and footer inside an article or section are not page-level landmarks.

The post is an article that can stand alone. The Basics block is a named section, so it appears as a region. The related links are an aside, which screen readers list as complementary content. The last box is a plain div because it has no meaning.

Check the outline with a landmarks list in a screen reader or browser tools.

html
<main>
  <article id="post">
    <h1>Learning HTML</h1>
    <section id="s1" aria-labelledby="h-basics"><h2 id="h-basics">Basics</h2><p>Tags and attributes.</p></section>
    <aside id="side"><h2>Related</h2><a href="#">CSS guide</a></aside>
    <div class="box">Only for styling</div>
  </article>
</main>

Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.

Key points

  • article stands on its own.
  • section groups a theme and needs a heading.
  • aside is related, removable content.
  • div carries no meaning; use it for styling.
  • Name a section to make it a region.

Common mistakes

  • Using section for every wrapper because it sounds semantic.
  • Using article and section with no headings.
  • Adding many landmarks with no names, which makes navigation noisy.

Follow-ups

  • What makes a section a region landmark?
  • Is a header inside an article a page-level banner?

Tips

  • State the meaning of each in one line, and say div means none.
  • Give the self-contained test for article.