Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the difference between <div> and <span>?

user-image
Question added by Osama Abu Rayyan , Web Developer / Front-End Web Developer , BloomThemez
Date Posted: 2013/08/12
Mark Guirguis
by Mark Guirguis , IT Specialist , FAB Concepts

div is a block element, span is inline.
This means that to use them semantically, divs should be used to wrap sections of a document, while spans should be used to wrap small portions of text, images, etc.
For example: This a large main division, with a small bit of spanned text! Note that it is illegal to place a block level element within an inline element, so: Sometext that I want to mark up ...is illegal.

محمد ماجد العوادلي
by محمد ماجد العوادلي , Software Developer , Kamar soft

'' is an inline element '' is a block element   The '' can be nested within '' The '' cannot be nested within ''   for Example:   Content-1 (first span).
Content-2 (second span).
Content-3 (third span).
Content-1 (first div) Content-2 (second div) Content-3 (third div)

mohammed Gomma
by mohammed Gomma , Senior software engineer , adsia.com

In brief : is a block element used to contain other elements and build regions in the page.
is an inline element to be added inline beside its previous or next element and didn't make new line unlike

Mohamad Kaakati
by Mohamad Kaakati , Co-Founder & Chief Technology Officer , BARQ FAST TECH Co

is a Container wich will contain your .
used to orgnize & customize the sections of your page, while is used to customize an element inside the page or the it self.
example: This is a Paragraphyou use CSS to do whatever you want to do with the word "Paragraph".
span { color: red; } All text within the will get the "Red" color.

Mohamed Hamed
by Mohamed Hamed , CTO , edTOMO, INC.

Let me make it easy for you.
They both are HTML tags.
The div is a block element.
span is inline.
This means that to use them semantically, divs should be used to wrap sections of a document, while spans should be used to wrap small portions of text, images, etc.
Note: that it is illegal to place a block level element within an inline element, if you know what I mean.
But: You cannot use div and span semantically as they don't have any meaning attached to them.
div is a meaningless generic block level elements while span is a meaningless generic inline element.
What do you think? A Puzzle eh? :) Regards Joe

URFI HISSAM
by URFI HISSAM , System Administrator , Ministry of Health

This a large main division,a small bit

Ansar Naseeh
by Ansar Naseeh , Senior Software Developer , fidhaps

div is used to design a block elements span used is used for small portion its inline design

Muhammad Bilal Ahmed
by Muhammad Bilal Ahmed , Senior Front End Developer , Seven Software Development

Hi, 

 

 Divs should be used to wrap sections of a document, Div tag and Span tag allow the web designer to create the text in various style. 

 

Div tags are block elements means they can hold other HTML elements. 

While Span tags cannot hold other HTML elements, they are not block elements, spans should be used to wrap small portions of text, images, etc.

 

Thanks.

 

mirza habeeb
by mirza habeeb , Application Support & Database Developer , Via Technology

The difference between span and div is that a span element is in-line and usually used for a small chunk of HTML inside a line (such as inside a paragraph) whereas a div (division) element is block-line (which is basically equivalent to having a line-break before and after it) and used to group larger chunks of code.

Rashid Anwar
by Rashid Anwar , senior php developer , sparx it solution pvt ltd.

div is a "block" element and span is an "inline" element.

The differntce lies in how the browser treat them to render on your pc.

browser renders two consecutive "block" elements one after another vertically. So you can not use two "block" elements side by side in normal way. 

for example your html containts two div as <div>Computer</div><div>Mobile</div>

browser will render above html as

Computer

Mobile

not as Computer Mobile

 

where as "inline" elements can be displayed side by side in a single line.

for example your html containts two span as <span>Computer</span><span>Mobile</span>

browser will render above html as

Computer Mobile

not as

Computer

Mobile

 

notice the difference the browser renders two consicutive block elements in two different lines where inline elements are rendered in a single line.

you can make a block element behaves like "inline" element and vice-versa by setting its display property either block, inline, inline-block etc..

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.