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

Updated: 04/02/2019 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, 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 an 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 an 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>