freecoding.school100% FREE · NO SIGNUP
Markup CityISSUE #22 of 39

div · the generic container

Tagg the BuilderVSThe Unclosed Tag
Tagg the Builder says<div> is a generic block container with no meaning of its own — a hook for grouping and styling.

The <div> is the all-purpose box. It carries no semantic meaning; it exists to group elements so you can style or position them together, or target them with JavaScript.

Because it's meaningless, prefer a semantic element (<section>, <article>, <nav>) when one fits. Reach for <div> only when you genuinely just need a styling wrapper. Its inline cousin is <span>.

Power-ups you unlock

The Unclosed Tag attacks — common mistakes

Boss battleWrap two paragraphs in a <div class="card"> and give the card a border and padding. Then ask yourself: could this be a <section> instead?

Example code

<!doctype html>
<html><head><meta charset="utf-8">
<style>.card{border:1px solid #2a1d4a;border-radius:6px;padding:14px;background:#0c081a}</style>
</head>
<body style="background:#06040d;color:#e6e0ff">
  <div class="card">
    <h2 style="color:#b388ff;margin:0 0 6px">a grouped card</h2>
    <p>the div groups these for styling.</p>
  </div>
</body></html>
▶ Open the interactive comic issue
‹ Block Vs Inline · The Two Flow ModesClasses · Reusable Hooks ›