What is the difference between a DIV tag and a SPAN tag? These two tags are often used inter-changeably by developers for different reasons.
The basic difference between the two is their default behavior. The DIV tag is a block level element and can be used as container for other tags. On the other hand, SPAN tag is an inline element and should only contain contents. These default behaviours can of course be altered by CSS definitions, but are default in any browser context. As an example, if you want to align text within these tags use the following CSS attributes:
Using DIV tag:
Using SPAN tag:
The DIV tag takes as much of the width of the page as it can. It blocks out the whole section of the page, so that anything following it has to go to the next line beneath it. The SPAN tag takes as little space as possible, only enough to contain its content. For the purpose of illustration, I put a border around the element so that you can see the difference:
DIV tag is also used to define logical divisions of page content. It also allows CSS to be defined for whole section of HTML. A SPAN tag is not intended to contain other tags but rather to allow localized styling. This is especially useful when combined with CSS classes.
Alternatively, P tag is a block level element while STRONG tag is an inline element.