Page 1 of 1

Difference between DIV-tag and SPAN-tag

Posted: Mon Jan 07, 2013 8:34 pm
by mister_v
Hi,

Can anyone explain me the difference between

Code: Select all

<DIV>
and

Code: Select all

<SPAN>
.

Thanks,

Re: Difference between DIV-tag and SPAN-tag

Posted: Mon Jan 07, 2013 9:14 pm
by chris
<DIV> is more like a paragraph and <SPAN> is not.

The DIV element gives you the chance to define the style of whole sections of the HTML. You can define a division of your page as a call out and give that area a different style from the surrounding text.

Because the CENTER element has been deprecated in HTML 4.0 and is obsolete in HTML5, it is a good idea to start using

Code: Select all

<div style="text-align: center;">
to center the content inside your DIV.

The SPAN element has very similar properties to the DIV element, in that it changes the style of the text it encloses. But without any style attributes, the SPAN element won't change the enclosed items at all.

Code: Select all

In a sentence you can change <span style="color: red;">a word to red</span> without breaking with spaces and newlines.
Hopes this clears things up.