Difference between a <div> and <span> HTML tag

Updated: 04/26/2017 by Computer Hope

HTML div tagHTML span tagThe 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, if you want to adjust a small portion of text and not break it out of the current line, you should use a <span>. If you need to modify a large division, the height, move an element, or contain other elements, you should use a <div>.

Example of a HTML <span> tag

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 a HTML <div> tag

An example of a div tag that has 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>An example of a div tag that has a maximum width of 200 pixels and a silver background.</p>
</div>