Sectioning Content
HTML5
The <section> element represents a thematic grouping of content, typically with a heading. Use it to divide your content into meaningful sections that have a clear theme or purpose. Unlike <article>, a section is not necessarily self-contained or independently distributable.
Interactive code playground requires JavaScript. Here's the code:
<article>
<h1>Complete Guide to Web Development</h1>
<section>
<h2>HTML Fundamentals</h2>
<p>HTML is the foundation of web development...</p>
</section>
<section>
<h2>CSS Styling</h2>
<p>CSS controls the visual presentation...</p>
</section>
<section>
<h2>JavaScript Interactivity</h2>
<p>JavaScript adds dynamic behavior...</p>
</section>
</article>
<!-- Thematically related content -->
The <section> element has no element-specific attributes.
This element supports all global attributes .
Dividing long-form content into logical sections:
Interactive code playground requires JavaScript. Here's the code:
<article>
<header>
<h1>The Complete JavaScript Handbook</h1>
<p>A comprehensive guide to modern JavaScript</p>
</header>
<section id="introduction">
<h2>Introduction</h2>
<p>JavaScript is a versatile programming language that powers the modern web...</p>
</section>
<section id="variables">
<h2>Variables and Data Types</h2>
<p>JavaScript provides several ways to declare variables...</p>
<h3>const and let</h3>
<p>Modern JavaScript uses const and let instead of var...</p>
</section>
<section id="functions">
<h2>Functions</h2>
<p>Functions are reusable blocks of code...</p>
</section>
<section id="conclusion">
<h2>Conclusion</h2>
<p>You now have a solid foundation in JavaScript...</p>
</section>
</article>
Different thematic sections on a landing page:
Interactive code playground requires JavaScript. Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Product Landing Page</title>
<style>
section { padding: 3rem 1rem; }
.hero { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; text-align: center; }
.features { background: #f9f9f9; }
.pricing { background: white; }
.testimonials { background: #f0f0f0; }
</style>
</head>
<body>
<section class="hero">
<h1>Amazing Product</h1>
<p>Transform your workflow with our innovative solution</p>
<button>Get Started</button>
</section>
<section class="features">
<h2>Features</h2>
<div>
<article>
<h3>Fast</h3>
<p>Lightning-fast performance</p>
</article>
<article>
<h3>Secure</h3>
<p>Enterprise-grade security</p>
</article>
</div>
</section>
<section class="pricing">
<h2>Pricing</h2>
<p>Choose the plan that's right for you</p>
</section>
<section class="testimonials">
<h2>What Our Customers Say</h2>
<blockquote>
<p>"This product changed my life!"</p>
</blockquote>
</section>
</body>
</html>
Organizing different parts of a blog post:
Interactive code playground requires JavaScript. Here's the code:
<article>
<header>
<h1>How to Build a REST API</h1>
<p>By Jane Developer | March 15, 2025</p>
</header>
<section id="overview">
<h2>Overview</h2>
<p>In this tutorial, we'll build a complete REST API using Node.js and Express...</p>
</section>
<section id="prerequisites">
<h2>Prerequisites</h2>
<ul>
<li>Node.js installed</li>
<li>Basic JavaScript knowledge</li>
<li>Understanding of HTTP</li>
</ul>
</section>
<section id="setup">
<h2>Project Setup</h2>
<p>First, let's create a new project directory...</p>
</section>
<section id="implementation">
<h2>Implementation</h2>
<h3>Creating Routes</h3>
<p>We'll start by defining our API routes...</p>
<h3>Database Integration</h3>
<p>Next, we'll connect to a database...</p>
</section>
<section id="testing">
<h2>Testing</h2>
<p>Let's test our API endpoints...</p>
</section>
<footer>
<p>Tags: #nodejs #api #tutorial</p>
</footer>
</article>
Different information sections on a product page:
Interactive code playground requires JavaScript. Here's the code:
<main>
<h1>Wireless Bluetooth Headphones</h1>
<section class="product-overview">
<h2>Product Overview</h2>
<img src="headphones.jpg" alt="Bluetooth headphones" style="width: 100%; max-width: 400px;">
<p class="price" style="font-size: 2rem; color: #e91e63;">$199.99</p>
<button>Add to Cart</button>
</section>
<section class="features">
<h2>Features</h2>
<ul>
<li>Active Noise Cancellation</li>
<li>30-hour battery life</li>
<li>Bluetooth 5.0</li>
<li>Comfortable over-ear design</li>
</ul>
</section>
<section class="specifications">
<h2>Technical Specifications</h2>
<table>
<tr><th>Driver Size</th><td>40mm</td></tr>
<tr><th>Frequency Response</th><td>20Hz - 20kHz</td></tr>
<tr><th>Weight</th><td>250g</td></tr>
</table>
</section>
<section class="reviews">
<h2>Customer Reviews</h2>
<p>⭐⭐⭐⭐⭐ 4.5 out of 5 (234 reviews)</p>
</section>
</main>
Sections used with tabs or accordions:
Interactive code playground requires JavaScript. Here's the code:
<article>
<h1>Web Development Course</h1>
<div role="tablist">
<button role="tab" aria-selected="true" aria-controls="overview-panel">Overview</button>
<button role="tab" aria-selected="false" aria-controls="curriculum-panel">Curriculum</button>
<button role="tab" aria-selected="false" aria-controls="instructor-panel">Instructor</button>
</div>
<section id="overview-panel" role="tabpanel" aria-labelledby="overview-tab">
<h2>Course Overview</h2>
<p>Learn modern web development from scratch. This comprehensive course covers HTML, CSS, JavaScript, and more...</p>
</section>
<section id="curriculum-panel" role="tabpanel" aria-labelledby="curriculum-tab" hidden>
<h2>Curriculum</h2>
<ul>
<li>Week 1: HTML Fundamentals</li>
<li>Week 2: CSS Styling</li>
<li>Week 3: JavaScript Basics</li>
</ul>
</section>
<section id="instructor-panel" role="tabpanel" aria-labelledby="instructor-tab" hidden>
<h2>Meet Your Instructor</h2>
<p>Jane Developer has 10 years of experience in web development...</p>
</section>
</article>
Organizing different widgets or data on a dashboard:
Interactive code playground requires JavaScript. Here's the code:
<main>
<h1>Analytics Dashboard</h1>
<section class="metrics">
<h2>Key Metrics</h2>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;">
<div style="border: 1px solid #ddd; padding: 1rem;">
<h3>Total Users</h3>
<p style="font-size: 2rem;">12,345</p>
</div>
<div style="border: 1px solid #ddd; padding: 1rem;">
<h3>Revenue</h3>
<p style="font-size: 2rem;">$54,321</p>
</div>
<div style="border: 1px solid #ddd; padding: 1rem;">
<h3>Conversion</h3>
<p style="font-size: 2rem;">3.2%</p>
</div>
</div>
</section>
<section class="charts">
<h2>Performance Charts</h2>
<p>[Chart visualization would go here]</p>
</section>
<section class="recent-activity">
<h2>Recent Activity</h2>
<ul>
<li>New user registered - 5 min ago</li>
<li>Order #1234 completed - 10 min ago</li>
</ul>
</section>
</main>
Understanding when to use each element:
<!-- Use <section> for thematic content with a heading -->
< p > Thematically related content... </ p >
<!-- Use <div> for non-semantic grouping (styling/scripting) -->
<!-- Layout structure, no semantic meaning -->
<!-- Use <article> for self-contained, independently distributable content -->
< p > Complete, standalone content... </ p >
<!-- Common pattern: Article containing sections -->
Every section should have a heading (h1-h6):
<!-- Good: Section with heading -->
<!-- Avoid: Section without heading -->
< p > Content without a clear theme... </ p >
<!-- If no heading needed, use div instead -->
< p > Content for styling purposes only... </ p >
Maintain proper heading hierarchy within sections:
<!-- Good: Proper hierarchy -->
< h1 > Main Article Title </ h1 >
<!-- Avoid: Skipping heading levels -->
< h5 > Subsection </ h5 > <!-- Skipped h3 and h4 -->
Not every group of content needs to be a section:
<!-- Overuse: Too many sections -->
<!-- Better: Use sections purposefully -->
< div class = " content-wrapper " >
Sections work well with other semantic elements:
< p class = " subtitle " > Additional context </ p >
<!-- Related information -->
The <section> element has an implicit ARIA role of region when it has an accessible name:
<!-- Has region role because of aria-label -->
< section aria-label = " User settings " >
<!-- Has region role because of aria-labelledby -->
< section aria-labelledby = " settings-heading " >
< h2 id = " settings-heading " > Settings </ h2 >
<!-- Generic role if no accessible name -->
For important sections, provide accessible names:
<!-- Using aria-labelledby (preferred when visible heading exists) -->
< section aria-labelledby = " features-heading " >
< h2 id = " features-heading " > Features </ h2 >
<!-- Using aria-label (when heading doesn't fully describe the section) -->
< section aria-label = " Product pricing and plans " >
< h2 > Choose Your Plan </ h2 >
Sections contribute to the document outline:
< h1 > Main Title </ h1 > <!-- Level 1 -->
< h2 > Section 1 </ h2 > <!-- Level 2 -->
< h3 > Subsection </ h3 > <!-- Level 3 -->
< h2 > Section 2 </ h2 > <!-- Level 2 -->
Browser Version Chrome 5+ Firefox 4+ Safari 5+ Edge All versions IE 9+
Self-contained content that can contain sections.
Learn more →
Tangentially related content.
Learn more →
<!-- Wrong: Section for styling only -->
< section class = " clearfix " >
< section class = " column-left " > Content </ section >
< section class = " column-right " > Content </ section >
<!-- Correct: Div for non-semantic styling -->
< div class = " column-left " > Content </ div >
< div class = " column-right " > Content </ div >
<!-- Correct: Section with semantic meaning -->
< p > Thematic content... </ p >
<!-- Avoid: No heading -->
<!-- Better: Include heading -->
< p > Related content... </ p >
<!-- Or use div if no heading is appropriate -->
< p > Content for styling purposes... </ p >
<!-- Wrong: Using section for independent content -->
< p > Complete standalone article... </ p >
<!-- Correct: Use article for independent content -->
< p > Complete standalone article... </ p >
<!-- Correct: Sections within article -->