HTML

Div vs Span: Difference Between Block and Inline Elements in HTML

What’s the difference between div and span? Learn the concept of block and inline elements in HTML with practical examples for building layouts.

RazakTerra
Reading time
1 min read
Comments
Discussion
Div vs Span: Difference Between Block and Inline Elements in HTML
On this page
  1. Block vs Inline
  2. When to Use Each
  3. Example
  4. Quick Tips

<div> and <span> are two of the most commonly used tags in HTML. They don’t have any special meaning on their own, they’re mainly used as containers for styling or structure. The key difference is how they behave on the page.

Block vs Inline

Block elements (like <div>)

  • Start on a new line
  • Take up the full width available
  • Can contain other block or inline elements
HTML
<div>This is a block element</div>
<div>This appears on the next line</div>

Inline elements (like <span>)

  • Stay on the same line
  • Only take up as much width as needed
  • Usually used inside paragraphs or other text
HTML
<p>This is a <span>highlighted</span> word inside a sentence.</p>

When to Use Each

Element Type Best Used For
<div> Block Layout sections, cards, containers
<span> Inline Styling a few words inside a sentence

Example

HTML
<div class="card">
  <h2>Product Title</h2>
  <p>This is a <span class="price">$29</span> product.</p>
</div>

Quick Tips

  • Prefer semantic tags (<article>, <section>, etc.) over too many <div>s when possible.
  • Use <span> only when you need to style or target a small part of text.
  • Don’t use <div> or <span> if a more meaningful tag already exists.

Written by

Razak

Writes about the web, slowly, and builds small tools on the side.

Discussion

Comments

Loading comments…

Keep reading