Difference between DIV-tag and SPAN-tag

Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Difference between DIV-tag and SPAN-tag

Post by mister_v »

Hi,

Can anyone explain me the difference between

Code: Select all

<DIV>
and

Code: Select all

<SPAN>
.

Thanks,
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: Difference between DIV-tag and SPAN-tag

Post 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.
Post Reply