A thematic grouping of content, typically with a heading. Use for chapters, tabbed panels, numbered sections, or any content that would appear in an outline.
Usage
Use the <section> element for:
- Chapters or thematic groups within an article
- Each panel in a tabbed interface
- Major sections of a homepage (hero, features, testimonials)
- Numbered or labeled sections in documentation
A section should have a heading that identifies its content. If it has no heading, it is not a section: in VB, group the content with a layout element (<layout-stack>, <layout-cluster>, …) or put data-layout on the parent, rather than reaching for a <div>.
Examples
Default
Basic section with heading and content.
<section> <h2>Features</h2> <p>Our product offers a comprehensive set of features designed to improve your workflow.</p></section>
.alt
Alternate background for visual rhythm between stacked sections.
<section class="padded"> <h2>Regular Section</h2> <p>Default background section.</p></section><section class="alt padded"> <h2>Alternate Section</h2> <p>Raised background creates visual separation.</p></section><section class="padded"> <h2>Regular Section</h2> <p>Default background section.</p></section>
.bordered
Top border for visual separation.
<section> <h2>Previous Section</h2> <p>Content above the border.</p></section><section class="bordered"> <h2>Bordered Section</h2> <p>This section has a top border to separate it from above content.</p></section>
.hero
Hero section with centered content and minimum height.
<section class="hero"> <h1>Welcome to Vanilla Breeze</h1> <p>A layered HTML component system for modern web development</p> <footer> <button type="button">Get Started</button> </footer></section>
.grid
Auto-fit grid layout for card grids.
<section class="grid"> <article class="card"> <h2>Feature One</h2> <p>Description of the first feature.</p> </article> <article class="card"> <h2>Feature Two</h2> <p>Description of the second feature.</p> </article> <article class="card"> <h2>Feature Three</h2> <p>Description of the third feature.</p> </article></section>
.padded
Vertical padding for spacing between sections.
<section class="padded"> <h2>Padded Section</h2> <p>Extra vertical padding creates visual separation between sections.</p></section>
.full
Generous block and inline padding for page-level bands. Despite the name it does not break out to the viewport: the section stays as wide as its container.
<section class="full"> <h2>Spacious Section</h2> <p>Generous padding on all sides; as wide as its container.</p></section>
.contained
Max-width container for centered content.
<section class="contained"> <h2>Contained Section</h2> <p>Content is centered with a comfortable maximum width.</p></section>
Sections within an article
Thematic grouping of content within an article.
<article class="blog"> <header> <h2>Complete Guide to Semantic HTML</h2> <p>A comprehensive tutorial</p> </header> <section> <h3>Introduction</h3> <p>Semantic HTML provides meaning to web content.</p> </section> <section> <h3>Sectioning Elements</h3> <p>HTML5 introduced several sectioning elements.</p> </section> <section> <h3>Conclusion</h3> <p>Using semantic elements improves accessibility.</p> </section></article>
Page-Band Attributes
For landing pages built from stacked full-width bands, sections also take a few data attributes.
data-padding
Fluid block padding that scales with the viewport. Bare data-padding is the normal step; small, xsmall and none step down. data-padding-start="none" and data-padding-end="none" drop one side so neighbouring bands butt together.
<section data-padding>…</section><section data-padding="small">…</section><section data-padding="xsmall">…</section><section data-padding data-padding-end="none">…</section>
section.hero[data-bleed]
The hero's background extends up behind the site header (body > header), and that header turns transparent. Set data-scrolled on <html> from your own script, for example an IntersectionObserver on the hero, to give the header its surface back once the hero scrolls away. The overlap height comes from --site-header-height (default 4rem).
<body> <header>…site nav…</header> <main> <section class="hero" data-bleed> <h1>Hero behind the header</h1> </section> </main> <script> const hero = document.querySelector('section.hero[data-bleed]'); new IntersectionObserver(([entry]) => { document.documentElement.toggleAttribute('data-scrolled', !entry.isIntersecting); }).observe(hero); </script></body>
Check text contrast on the header while it sits over the hero background.
data-angle
Skews the section's background along one edge for an angled transition: down and down-strong slope the top edge, up and up-strong the bottom edge. Extra block padding keeps content clear of the slope. The slope mirrors under dir="rtl". Give the section a background, otherwise there is nothing to skew.
<section data-angle="down" data-padding>…</section><section data-angle="up-strong" data-padding>…</section>
Hairline rules: section > hr[data-position]
A direct-child <hr data-position="top"> or data-position="bottom" becomes an edge-to-edge rule pinned to that edge of the section, taken out of the content flow.
<section data-padding> <hr data-position="top" /> <h2>Top hairline</h2></section>
Container Behavior
Every <section> (like main, article and most asides) is a size query container: VB gives it container-type: inline-size. Two consequences:
- Container units and queries resolve against the section.
cqi units and @container queries inside it measure the section, not the viewport.
- A content-sized section can collapse. Size containment ignores the section's content when working out its width. As a flex or grid item that is sized by its content (a
display: flex row, an align-items: center column, an auto track), the section shrinks to zero width. VB already undoes this inside layout-cluster, layout-reel, centred layout-cover and aligned layout-stack.
Elsewhere, opt out by setting container-type: normal on the section in your own CSS, or give it an explicit size. Inside the layouts above, add data-container to a section to keep it as a container on purpose.
.toolbar > section { container-type: normal;}
Variants
| Class |
Description |
.padded |
Vertical padding (--size-xl) for spacing |
.full |
Generous block (2xl) and inline (l) padding; no breakout |
.contained |
Max-width 1200px, centered with horizontal padding |
.alt |
Raised background color for visual alternation (block borders in forced-colors mode) |
.bordered |
Top border with padding for visual separation |
.hero |
Centered content, minimum 50vh height, generous padding |
.grid |
Auto-fit grid layout for responsive card arrangements |
| Attribute |
Values |
Description |
data-padding |
(bare), small, xsmall, none |
Fluid block padding |
data-padding-start / data-padding-end |
none |
Remove block-start or block-end padding |
data-bleed |
boolean, on section.hero |
Background extends behind body > header, which turns transparent until <html data-scrolled> |
data-angle |
down, up, down-strong, up-strong |
Skewed background edge with padding compensation; mirrors in RTL |
data-container |
boolean |
Keep the section a query container inside content-sized layouts |
hr[data-position] (child) |
top, bottom |
Edge-to-edge hairline pinned to that edge |
Accessibility
- A
<section> is a region landmark only when it has an accessible name, e.g. aria-labelledby pointing at its heading (or aria-label). A heading alone does not make it a landmark.
- Name only the few sections a user would want to jump to. Naming every section floods the landmark list and makes it less useful.
- Always include a heading (h2-h6) so the section shows up in heading navigation
- Use appropriate heading levels - don't skip levels for visual styling
- If a section has no meaningful heading, it is not a section: use a VB layout element or
data-layout on the parent
- Hero sections should still have a proper h1 for the page title
- Grid sections should use semantic elements (like
<article>) for grid items when appropriate
- In forced-colors mode backgrounds are flattened, so
.alt sections gain a system-colour border to stay distinct
Named Region Example
<section aria-labelledby="pricing-title"> <h2 id="pricing-title">Pricing</h2> …</section>
Related
<article> - For self-contained, distributable content (section is for thematic grouping)
<aside> - For tangentially related content (section is for primary content)
<main> - Sections are often children of main
<header> - Sections can have their own headers
<hgroup> - For section headings with subtitles