<span> and <div> — Generic Containers
Not everything on a page maps neatly to a semantic element like
<nav> or <article>. For the rest, HTML gives you two purely
generic containers: <div> for block-level grouping, and <span>
for inline grouping. Neither carries any inherent meaning — they
exist purely as styling and scripting hooks.
<div> — Generic Block Container
<div> groups block-level content with no semantic meaning of its
own. It's the workhorse of CSS layout — cards, containers, grid
cells, and wrapper elements are almost always <div>s.
div.html
<div class="card">
<img src="avatar.jpg" alt="User avatar">
<div class="card-body">
<h3>Jane Doe</h3>
<p>Frontend Engineer</p>
</div>
</div><span> — Generic Inline Container
<span> does the same job as <div> but for inline content — it
wraps a piece of text (or other inline elements) so you can target it
with CSS or JavaScript, without breaking the flow of the surrounding
line.
span.html
<p> Your order total is <span class="price">$42.50</span>, including <span class="tax">$3.50</span> in tax. </p>
When to Reach for Them vs Semantic Elements
The rule of thumb: always check if a semantic element fits first.
Only fall back to <div>/<span> when none of the meaningful
elements apply.
Situation | Better choice |
|---|---|
Wrapping the page's main navigation |
|
A self-contained blog post or comment |
|
A sidebar of related links |
|
Grouping a card layout with no semantic role |
|
Highlighting a price inline for styling only |
|
Marking inline text as important |
|
<div>s (sometimes called "div soup") gives screen readers and search engines nothing to work with — every region looks the same. Reach for <header>, <nav>,<main>, <article>, <section>, <aside>, and <footer> wherever they genuinely apply, and reserve <div> for the layout glue in between.Styling Hooks via class
Since <div> and <span> carry no meaning, class (and sometimes
id) is how you make them useful — as targets for CSS selectors and
JavaScript queries.
styling-hooks.html
<style>
.badge { padding: 2px 8px; border-radius: 999px; background: #eee; }
.badge--new { background: #d1f4e0; color: #0a7c42; }
</style>
<p>
Version 2.0 <span class="badge badge--new">New</span> is now available.
</p>Quick Reference
Element | Display type | Use for |
|---|---|---|
| Block | Generic grouping of block-level content (layout, containers) |
| Inline | Generic grouping of inline content (styling a word/phrase) |
Neither element implies any meaning to browsers, search engines, or assistive technology.
Always ask "is there a semantic element that fits better?" before defaulting to
<div>/<span>.classandidare what make these generic containers useful as targeting hooks.
<div>/<span> isn't "bad HTML" — every real site uses plenty of both. The goal is just to not use them as a substitute for semantic elements that already communicate the right meaning.