Sub topic 7
Content sections: organizing the main message
This chapter assumes you can write basic HTML tags and attributes, use CSS selectors and properties, and open a page in a browser with its developer tools. It covers the part of the page that sits between the hero and the footer: the content sections that carry the main message.
What a content section is
A content section is a block of related content inside <main> that has a single purpose and usually its own heading. On the Acme Bakery page, "Our specialties" is a content section. A real page might also have "How ordering works", "Customer reviews", and "Visit us".
The hero tells a visitor what the site offers. The content sections give the evidence and details that support that message. Each section answers one question a visitor is likely to have, and the order of the sections should follow the order in which those questions occur.
The section element and when to use it
The <section> element groups content that belongs together thematically. The rule of thumb is this: use <section> when the block has a heading that names its topic. If you cannot give the block a meaningful heading, it probably is not a section.
<main>
<section class="hero">
<h1>Fresh bread, baked every morning</h1>
<p>Order ahead and pick up warm loaves on your way to work.</p>
<a href="/menu">See the menu</a>
</section>
<section>
<h2>Our specialties</h2>
<p>Sourdough, rye, and seasonal pastries.</p>
</section>
<section>
<h2>How ordering works</h2>
<p>Choose your loaves, pick a time, and collect them at the counter.</p>
</section>
</main>Three points about this markup:
- Every content section starts with an
<h2>. The page's single<h1>lives in the hero, so the sections below it sit one level down. - A
<section>without an accessible name is exposed to assistive technology as a generic grouping. Once it has a name, browsers expose it as aregionlandmark, which screen reader users can jump to. The next chapter sections on accessibility cover this in more detail. - The sections are siblings. They are not nested inside one another unless one section is truly a subdivision of another.
Choosing between section, article, aside, and div
Several elements can wrap content, and picking the right one matters for both meaning and navigation.
| Element | Use it for | Typical example |
|---|---|---|
| `<section>` | A themed group of content with a heading | "Our specialties" |
| `<article>` | A self-contained item that makes sense on its own, such as one you could syndicate | A blog post, a review, a news item |
| `<aside>` | Content related to the surrounding content but not essential to it | A sidebar tip, a pull quote |
| `<div>` | A wrapper with no meaning, used only for styling or scripting | A container that centers content |
If you are unsure, ask two questions. First, would the block still make sense if it were copied to another site? If so, <article> fits. Second, does the block have a heading and a single theme? If so, <section> fits. If the answer to both is no and you only need a hook for CSS, use <div>.
A common mistake is replacing every <div> with <section>. A <section> that exists only to center a column or add padding adds noise to the landmark list for screen reader users. Keep <div> for pure layout wrappers.
Headings inside sections
The heading hierarchy from earlier in the tutorial applies here. Each content section gets an <h2>. When a section has subparts, those get <h3> headings, and so on.
<section>
<h2>Our specialties</h2>
<p>Everything is made from scratch each morning.</p>
<article>
<h3>Sourdough</h3>
<p>A 36-hour ferment gives it a tangy crust.</p>
</article>
<article>
<h3>Rye</h3>
<p>Dense, dark, and good with butter.</p>
</article>
</section>Do not choose a heading level for its size. If an <h2> looks too large, change its font size in CSS. Skipping from <h2> to <h4> breaks the outline, and screen reader users who navigate by heading will find a gap that suggests missing content.
A section pattern worth reusing
Most content sections follow the same shape: a heading, an optional short introduction, and a body made of repeated items or a block of text. Because the shape repeats, you can write the CSS once.
<section class="specialties" aria-labelledby="specialties-title">
<h2 id="specialties-title">Our specialties</h2>
<p class="section-intro">Everything is made from scratch each morning.</p>
<div class="card-grid">
<article class="card">
<h3>Sourdough</h3>
<p>A 36-hour ferment gives it a tangy crust.</p>
</article>
<article class="card">
<h3>Rye</h3>
<p>Dense, dark, and good with butter.</p>
</article>
<article class="card">
<h3>Seasonal pastries</h3>
<p>The menu changes with the fruit available.</p>
</article>
</div>
</section>The aria-labelledby attribute points to the heading's id. This gives the section an accessible name that matches its visible heading, so the region landmark is announced as "Our specialties". Reusing the visible heading avoids a hidden label that could drift out of sync with it.
Styling sections consistently
Two decisions make a stack of sections look intentional: vertical rhythm and a readable width.
main > section {
padding: 3rem 1.5rem;
}
main > section > * {
max-width: 60rem;
margin-left: auto;
margin-right: auto;
}
.section-intro {
margin-top: 0.5rem;
margin-bottom: 2rem;
color: #444;
}
.card-grid {
display: grid;
gap: 1.5rem;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}
.card {
padding: 1.25rem;
border: 1px solid #ddd;
border-radius: 0.5rem;
}The first rule gives every top-level section the same vertical padding. The second keeps text lines to a comfortable length by limiting the width of each direct child and centering it, while the section's background can still run edge to edge. The card grid uses the auto-fit pattern from the layout chapter, so cards wrap to as many columns as fit.
Note that main > section > * also constrains the hero's children if the hero is a <section> directly inside <main>. If the hero uses its own two-column grid, exclude it with main > section:not(.hero) > *, or give the hero its own width rules.
Ordering sections to match the visitor's questions
The sequence of sections is a content decision, and it affects how well the page persuades. A reliable order for a small business page is:
- What you offer, in the hero.
- The details of the offer, such as products or services.
- How to get it, such as ordering steps or pricing.
- Proof that it is good, such as reviews or credentials.
- A final prompt to act, such as a contact or order link.
Not every page needs all five. A page with too many sections dilutes the message, so cut any section that does not answer a question a visitor is likely to ask.
Common errors
- Sections with no heading. Without a heading, a
<section>has no name and no place in the outline. Add a heading or use a<div>. - Multiple
<h1>elements. Each content section is tempting to start with an<h1>. Keep one<h1>per page, in the hero, and use<h2>for sections. - Using sections as layout wrappers. Wrapping a section in extra
<section>elements to add padding pollutes the outline. Use<div>for that. - Landmark overload. If every block has
aria-labelledby, a screen reader's landmark list becomes long and loses value. Name the sections that a visitor would plausibly want to jump to, and leave minor groupings unnamed. - Heading text that says nothing. "More" or "Details" gives no context in a heading list. Write headings that make sense when read alone.
Exercises
Exercise
A block on your page holds a single customer review that could be reprinted on another site. It has a heading. Which element should wrap it, and which heading level should the heading use if the review sits inside a "Reviews" section whose heading is an h2?
Show answer
Use <article>, because the review is self-contained and makes sense on its own. Its heading should be an <h3>, one level below the h2 of the "Reviews" section.
Exercise
You have a <section> that contains only a centered column of text and has no heading. It is there to add padding. What is wrong with it, and what should you use instead?
Show answer
A section with no heading has no name and no place in the outline, and it adds an unhelpful entry to the landmark list. Replace it with a <div> and style the padding with CSS.
Exercise
Write the opening tag and heading for a "Visit us" section so that screen readers announce the region as "Visit us".
Show answer
<section aria-labelledby="visit-title"> followed by <h2 id="visit-title">Visit us</h2>. The aria-labelledby value must match the heading's id.