HTML · The document layer
What is the difference between div and span?
Short answer
div is a block-level generic container and span is an inline generic container. Both carry no meaning, so use them only when no semantic element fits.
Neither element has a role beyond a generic container. A div is useful for grouping blocks that need styling or scripting, and a span is useful for wrapping a run of text inside a paragraph.
<div class="card">
<p>
Your plan renews on
<span class="date">28 October</span>.
</p>
</div>When to avoid them
- Use nav instead of a div for major navigation
- Use button instead of a div with a click handler
- Use header, main and footer instead of divs with those class names
- Use ul and li instead of a stack of divs when the content is a list
- Use label and input instead of spans and divs for form controls
A page built mostly from divs is often called div soup. It works visually but gives assistive technology and maintainers almost no information about the structure.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1When is a div the right choice?
- 2What does div soup mean?
- 3Does a span have any semantic meaning?
- 4Can a div replace a button if you add ARIA?
Say it in the interview
div is a generic block container and span is a generic inline container. Neither carries meaning, so I use them for styling or scripting only when no semantic element fits. I reach for nav, button, header or ul instead when the content has a clear meaning. A class called button on a div does not make it accessible; it is still a generic element without native keyboard behaviour.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live HTML mock interview and get scored feedback on depth, clarity and confidence.