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.
- Reading time
- 1 min read
- Comments
- Discussion

On this page
<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
<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
<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
<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.
Keep reading
Read next
1 minBest Practices for Writing Clean and Valid HTML
A collection of HTML best practices including proper indentation, naming, W3C validation, and common beginner mistakes you should avoid.
Read article
2 minGetting to Know HTML Iframe: How to Embed YouTube and Google Maps
How to use the HTML <iframe> tag to embed content from other sites, like a YouTube video or a Google Map, inside your own page.
Read article
1 minHow to Create Forms in HTML for Beginners
A beginner's guide to HTML forms: how the <form> tag sends data for logins, sign-ups and contact messages, starting from the basics.
Read article
Discussion
Comments
Loading comments…