Difference Between <div> and <section>
In HTML, both <div>
and <section>
are used to group content, but they serve different purposes semantically.
What is <div>?
The <div>
element is a generic container with no semantic meaning. It is mainly used for layout and styling with CSS or JavaScript.
<div class="header">
<h1>Welcome</h1>
</div>
What is <section>?
The <section>
element is a semantic container used to group related content under a thematic grouping, typically with a heading.
<section>
<h2>About Us</h2>
<p>We are a software company...</p>
</section>
Key Differences
Aspect | <div> | <section> |
---|---|---|
Semantic Meaning | None | Yes |
Usage | Generic container | Thematic content block |
SEO/Accessibility | Less helpful | More helpful |
Heading Required? | No | Recommended |
When to Use What?
- Use
<section>
for grouped content that forms a logical block, often with a heading. - Use
<div>
when you simply need a container for styling or scripting purposes without implying structure.