Lesson 33 of 51 · Module 5, lesson 6 of 7 · 3 min

Sections, articles and asides

Describe the shape of your content with article, section and aside, each with a heading.

What you'll learn

  • When to use <article>, <section> and <aside>
  • How headings and these elements work together
  • When <div> is still the right choice

Why this matters

<main> says "the content is here". Inside it, three more elements describe the shape of that content. Used well, they make long pages clear for screen readers, search engines and other developers.

The three elements

ElementUse it forTest
<article>A complete, independent piece: a recipe, a blog post, a news story, a product cardWould it still make sense if you copied it alone to another website?
<section>One part of a bigger whole, with its own heading: "Ingredients", "Steps"Does it have a heading that names it?
<aside>Content beside the main text: a tip, a note, related linksCould you remove it without breaking the main text?

A recipe article

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tomato soup — Home Kitchen</title>
</head>
<body>
  <main>
    <article>
      <h1>Tomato soup</h1>
      <p>A warm soup for four people.</p>

      <section>
        <h2>Ingredients</h2>
        <ul>
          <li>Six tomatoes</li>
          <li>One onion</li>
        </ul>
      </section>

      <section>
        <h2>Steps</h2>
        <ol>
          <li>Cut the vegetables.</li>
          <li>Cook them for twenty minutes.</li>
        </ol>
      </section>

      <aside>
        <h2>Did you know?</h2>
        <p>Tomatoes are botanically a fruit.</p>
      </aside>
    </article>
  </main>
</body>
</html>

What you'll see: the title, the two sections with their lists, and the "Did you know?" note — one after the other, with no special look.

The recipe page: heading "Tomato soup", a paragraph, the section "Ingredients" with a bulleted list of two items, the section "Steps" with a numbered list of two steps, and a "Did you know?" note at the end.

Headings go with them

Give every <section>, <article> and <aside> a heading. The heading names the part, and it keeps your page outline clear (see Headings and the page outline). If a group has no natural heading, it is probably not a <section>.

A list of articles

A page that lists several recipes holds several articles, each complete in itself:

html
<main>
  <h1>All recipes</h1>
  <article>
    <h2>Tomato soup</h2>
    <p>Ready in thirty minutes.</p>
  </article>
  <article>
    <h2>Green salad</h2>
    <p>Ready in ten minutes.</p>
  </article>
</main>

When to use <div> instead

If you only need a group for styling, and it has no heading and no meaning of its own, use <div>. When you are unsure whether something is a <section>, choose <div> — a meaningless wrapper is better than a wrong meaning.

Try it yourself

  1. Select the recipe article and choose Try it.
  2. Add a third section, "Serving ideas", with a heading and a paragraph.
  3. Turn your own recipe page from the exercise into an <article> inside <main>, with sections.

Common mistakes

  • <section> without a heading. It becomes an unnamed box. Fix: add a heading, or use <div>.
  • <article> for parts that cannot stand alone, such as "Ingredients". Fix: that is a <section> of the article.
  • The main content inside <aside>. Fix: <aside> is only for side content.

Check yourself

  1. A blog post on a page of posts: <article> or <section>?
  2. What should every <section> have?
  3. You need a wrapper only for styling. Which element?

Answers

  1. <article> — it makes sense on its own.
  2. A heading.
  3. <div>.

Next: you now know the structure elements. The next lesson shows how to check your page the way many disabled people use it — without a mouse, and without looking.

Chat with us on WhatsApp