DIV SPAN8 min20 XP

div and span

Learn div and span with syntax-highlighted examples, live output, and Shiv AI.

div and span

When no semantic tag fits, use <div> and <span>. They are generic containers with zero semantic meaning — invisible to search engines. Use them only for CSS grouping.

div — Block Container

<div> is block-level: starts on a new line and takes full width. Use it to group multiple elements for CSS layout:

Example — div as a Card
<div class="card">
  <h3>HTML Lesson</h3>
  <p>Learn HTML from scratch.</p>
</div>

<div class="card">
  <h3>CSS Lesson</h3>
  <p>Style your HTML pages.</p>
</div>

HTML Lesson

Learn HTML from scratch.

CSS Lesson

Style your HTML pages.

Each div stacks vertically because div is block-level. CSS then styles it as a card.

span — Inline Container

<span> is inline: flows within text without line breaks. Use it to style part of a sentence:

Example — span for Inline Styling
<p>HTML was created in 
  <span style="color:orange;font-weight:bold">
    1991
  </span>
   by Tim Berners-Lee.
</p>

<p>Today 
  <span style="color:#22c55e;font-weight:bold">
    1.9 billion
  </span>
   websites use HTML.
</p>

HTML was created in 1991 by Tim Berners-Lee.

Today 1.9 billion websites use HTML.

span does not break the line — the text flows naturally. Only the styled word changes appearance.

When to Use div vs Semantic Tags

Decision Guidediv or semantic?
Is it a header?Use <header> not <div class="header">
Is it navigation?Use <nav> not <div class="nav">
Is it a blog post?Use <article> not <div class="post">
Just a CSS wrapper?Use <div> — this is the correct use case
Style one word inline?Use <span>
Divitis Problem

Using div for everything when semantic tags exist is called "divitis." It was common before HTML5. Modern employers and code reviews flag excessive div usage where semantic tags should be used instead.

div Has Zero SEO Value

Search engines completely ignore div and span. Every time you use a semantic tag instead of a div, you give Google one more signal about your content structure and intent.

Why div Exists

div was in HTML from the very beginning as a generic grouping element. With CSS it became the primary layout tool throughout the 1990s and 2000s. HTML5 semantic elements replaced most layout divs but div remains essential for CSS grouping with no semantic role.

CIWeb HTML Course • 22 Lessons • Free

Explain with Analogies

Shiv AI explains this lesson using only real-life analogies. No code at all.

Click the Explain tab to generate analogies automatically.
index.html
Live Preview
Start coding - Shiv AI monitors automatically

What is the key difference between div and span?

Explanationdiv is block-level — starts on a new line and takes full width. span is inline and flows within text. This is the fundamental display difference between them.
Build Challenge
div and span Layout
Build a page using div for card grouping and span for inline text highlighting.
Requirements (5 to pass)
div element
span element
class on div
semantic tag too
paragraph
solution.html
Preview
Community Wall
Lesson 11
0/500
0/20 lines
as
Recent Posts
Lesson 11 only

Support CIWeb + Get +50 AI Messages

Just Rs.11 gives you 50 extra Shiv AI messages and keeps CIWeb free for everyone.

AI
Shiv AI
Online