What is the difference between a <div> and <span> HTML tag?

Updated: 11/12/2023 by Computer Hope
HTML div tagHTML span tag

The primary difference between a div and a span is their default behavior. By default, a <div> is a block-level element and a <span> is an inline element. In other words, to adjust a small portion of text and not break it out of the current line, use a <span>. If you need to modify a large division, the height, move an element, or contain other elements, use a <div>.

Example of an HTML <span> tag

Below is an example of red text generated in HTML (HyperText Markup Language) using the <span> tag that keeps the text inline with the other text.

Example text that is red text and an example of a span tag.

HTML code

<p>Example text that is <span style="color:red;">red text</span> and an example of a span tag.</p>

Example of an HTML <div> tag

Below is an example of HTML text within a div tag that's not part of the text.

Example of a div tag with a maximum width of 200 pixels and a silver background.

HTML code

<div style="width: 200px; background-color:#E5E4E2;padding:10px;margin-bottom:2em;">
<p>Example of a div tag with a maximum width of 200 pixels and a silver background.</p>
</div>