When to Use <div> vs Semantic Elements
You'll learn: How to decide between a generic <div> container and a meaningful semantic element when structuring your HTML.
The Core Decision
Now that you know semantic elements like <header>, <nav>, <article>, and <section>, you might wonder: "When should I still use a plain <div>?" The answer is simple: use semantic elements when your content has meaning, use <div> when you only need a container for styling or layout.
Think of it like organizing a library. Semantic elements are like labeled sections: "Fiction," "Reference," "Children's Books." A <div> is like an unmarked box—useful for grouping things together, but it doesn't tell you what's inside.
When to Choose Semantic Elements
Use semantic HTML when the content has a clear role:
- Navigation links? →
<nav> - Main article content? →
<article> - Site footer? →
<footer> - A related image with caption? →
<figure>
These choices help screen readers, search engines, and other developers understand your page structure.
When <div> Is the Right Choice
Use <div> when you need a container purely for:
- Layout purposes (wrapping items to apply CSS Grid or Flexbox)
- Styling hooks (adding a background color to a group of elements)
- Generic grouping where no semantic element fits the content's meaning
For example, wrapping three cards in a container just to arrange them side-by-side? That's a <div> job—there's no semantic meaning to "three things in a row."
Key Takeaway: Ask yourself "Does this content have a meaningful role in my document?" If yes, use a semantic element. If you're just grouping for layout or styling, <div> is perfectly fine.