Article, Section and the Outline

Beginner · 8 min

When to use article, section and aside, why the HTML5 outline algorithm never worked, and how heading levels alone define the real document outline.

Before thisLandmarks and Page Layout Elements

Kevin Powell · 8 min

Article, Section and the Outline

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Kevin PowellReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • `<article>` is a self-contained piece that makes sense on its own: a blog post, a comment, a product card. `<section>` groups content around one theme and normally starts with a heading.
  • An unnamed `<section>` has no role in the accessibility tree. With `aria-labelledby` or `aria-label` it becomes a `region` landmark. In a test only the named one showed up.
  • The HTML5 outline algorithm, where nested sections reset heading levels, was never implemented by browsers. In a test, six `<h1>` elements (in the body, sections, an article, a nav and an aside) all reported level 1 and drew at 32px.
  • The outline that tools actually use comes from the heading levels you write: `h1`, `h2`, `h3`. Keep them sequential even inside `article` and `section`.
  • `article` and `section` don't change how text looks. Choosing one is a statement about meaning, which is why a section with no heading is a sign you want a `div`.

Pieces versus groups

Landmarks cover the big regions. Inside main, you’ll write many smaller pieces of content, and HTML has elements for the two most common shapes.

An article is a self-contained composition: one that would still make sense if you cut it out and pasted it somewhere else, like a newspaper article. A blog post, a forum post, a user comment, a product card in a list. Articles can nest, so a comment is an article inside the post’s article.

A section is a thematic grouping of content, normally with a heading. A chapter, a tab panel, the “Pricing” block on a landing page. It doesn’t stand alone. It’s a part of something larger.

A third, aside, is content tangentially related to what’s around it: a pull quote, a sidebar. When an aside sits at the top level of the page it is a complementary landmark, as seen in the landmarks lesson.

What each one does in the tree

I tested these in headless Chromium 159 and read the accessibility tree:

  • <article> is exposed as article, and when it has an aria-label the name is part of the entry (article "Post").
  • An unnamed <section> was exposed with nothing: only its heading and text appeared.
  • A <section aria-labelledby="h"> pointing at its heading became region "Named".

That last point matters. A region is a landmark, and landmarks should be rare. Kevin’s video touches this in its landmarks and region role chapters. Name a section when people would want to jump to it, and leave the rest unnamed.

The outline that never happened

Here’s the part that’s easy to get wrong, and it’s the “lie” in the video’s title. The HTML5 spec described an outline algorithm: each section, article, nav and aside would start a new outline level, so an <h1> inside a nested section would count as a lower-level heading. Authors were told they could use h1 everywhere. No browser or assistive technology implemented it. I checked how a current browser behaves.

In the test I wrote <h1> in six places: at the top of the body, in a section, in a nested section, in an article, in a nav and in an aside. The accessibility tree reported every one as heading [level=1], and every one was drawn at 32px with the same top margin. A nested article with an h2, h3, h4 inside showed levels 2, 3 and 4 exactly as written. The browser uses your numbers, not the nesting.

So the real outline is the one your heading levels draw. Treat section as a container with meaning and use h2 for its heading when the page’s h1 is above it. The headings lesson covers why you shouldn’t skip levels. The HTML Standard today defines the outline simply as “all headings in a document, in tree order”, and it calls a heading that jumps more than one level deeper than the one before it non-conforming (I read the sections chapter of the spec for this).

Choosing between them

A quick decision list:

  1. Would this piece make sense on its own, as a post or a card? article.
  2. Is it a themed group of content with a heading of its own? section, and name it only if it should be a landmark.
  3. Is it only a wrapper for styling or layout? A div, as the next lesson on generic containers explains.

The check is a heading. A section with no heading is a hint that you meant div. Neither article nor section changes how the text looks, so picking them is purely a statement of meaning.

What the video covers

The embed is Kevin Powell’s “HTML section elements are a lie (sort of)” (February 2022, about 8 minutes). Its chapters are the introduction (0:00), typical usage of sections (1:29), landmarks (2:15), the region role (2:43) and adding semantic meaning to sections (3:50). The title’s claim fits the landmark point above: a section isn’t a landmark unless it has a name. I could not read a transcript, so I describe only the chapter titles. The heading-level test and the nested outline checks are this lesson’s own. The deeper link, Dave Gray’s semantic tags video, has a chapter on article versus section at 10:01 and one on the HTML5 outliner at 21:04.

Where this fits

This follows landmarks and page layout elements and sets up generic containers. The outline also feeds social metadata and structured data, where a page’s title and sections are summarised for other systems.

Check yourself

  1. 01Should a blog comment be an `article`, a `section` or a `div`?

    An `article`, if it could be read on its own, for example syndicated elsewhere. A comment has an author, a date and a body, and an article can be nested inside another article. Use a `div` only if you need a styling hook and there is no standalone meaning.

  2. 02You write `<section><h1>Title</h1></section>` inside a page that already has an `h1`. Does the browser treat it as a second-level heading?

    No. In a test, an `h1` inside a nested `section` was reported at level 1 in the accessibility tree and was drawn at 32px, the same as the top one. The section-resets-heading-levels outline was specified but never shipped, so use `h2` for a section's heading.

  3. 03When does a `<section>` become a landmark?

    When it has an accessible name, for example `aria-labelledby` pointing at its heading. An unnamed section has no role. In a test, only the named `section` was exposed as `region`. Do not name every section, only the ones worth jumping to.

  4. 04How do you decide between `article`, `section` and `div`?

    Ask whether the piece stands alone (`article`), whether it is a themed group that deserves a heading (`section`), or whether it is only a wrapper for layout or styling (`div`). Sectioning elements say something about content, so use them when the statement is true.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark