Wednesday, 4 March 2015

span vs div

Span vs Div in html

Span is used to mostly used to pick from inline content i.e. suppose we want to pick a word("is") from <p>This is the line</p> tags and give different color to the "is". Then we might wanna wrap that word around with <span></span> tags and give span tag and id or class. We can then apply css style to that selected or grouped content inside of our style sheet or inline.

Also, span tags are inline. i.e. any content confined inside of the span tag will remain inline.

Div on the other hand I used as a collector or container for several html elements. Suppose we have couple of h1,p tags in our website and we want to add background color to all of them. Then, we can confine them inside of a div tag and apply css styles to the respective div tag. 

Div tag are block level tag. They change the content confined to block level.

You can Play more in the link given below: 

No comments:

Post a Comment