The <section> Element
What you'll learn: You'll discover how to group related content with <section> and understand when to use it instead of <div>.
What is a <section>?
The <section> element represents a thematic grouping of content, typically with its own heading. Think of it as a chapter in a book — each chapter covers a distinct topic but contributes to the whole story.
Unlike <article> (which wraps self-contained, standalone content), a <section> groups content that belongs together by theme but isn't necessarily independent. If your content wouldn't make sense when pulled out of context and viewed alone, it's probably a section rather than an article.
When to Use <section> vs <div>
Use <section> when:
- The content has a clear theme or topic
- It deserves its own heading
- It represents a meaningful part of your document's structure
Use <div> when:
- You need a container purely for styling or JavaScript
- There's no semantic meaning to the grouping
- You're just organizing layout visually
Real-World Analogy
Imagine a restaurant menu. The entire menu might be wrapped in <main>. Each category (Appetizers, Main Courses, Desserts) would be a <section> — they're thematic groups that make sense together but aren't standalone. Individual dish descriptions might be <article> elements if they're complete on their own.
A <div>, meanwhile, would be like the invisible columns or borders that help layout the menu — purely presentational, no meaning.
Example Structure (Concept Only)
A homepage might have sections for "Our Services," "Customer Testimonials," and "Contact Information" — each thematically distinct but part of the overall page.
Key Takeaway: Use <section> to organize content into meaningful thematic groups with headings; use <div> only when you need a generic container without semantic meaning.