-5

Possible Duplicate:
What is the difference between HTML tags DIV and SPAN?
Difference between div and span

Many people are asking me the same question and I don't know the answer. Could you please tell me what is the difference between div and span; the html tags?

What is the difference?
What make them different?

and some other possible answers you think is better for this. And, please give the code which will make span work as div using css

Community
  • 1
  • 1
LIGHT
  • 5,604
  • 10
  • 35
  • 78
  • All elements are the same really, just with different properties. A span behaves just like a div if you set `display: block;` as span is an inline element – Andy Nov 21 '12 at 14:07
  • http://stackoverflow.com/questions/9047939/difference-between-div-and-span – René Höhle Nov 21 '12 at 14:07

5 Answers5

7

div is a block level element, span is an inline element. That's basically the gist of it. ;)

To elaborate; the div element's default styling is to be block level. That means it can contain other block level elements as well as in-line elements. The span element's default styling is to be in-line, which means block level elements can contain it, but it can't contain block level elements. However, both of these can be altered using CSS, so you could have an inline div and a block level span!

Bear in mind that although you might be able to get a better content layout by making spans block and divs inline, if you try to include a block level element inside an element such as span, the HTML validator might throw errors at you as technically those elements shouldn't be appearing there.

By 'block level' I mean it's a block of content and forces other blocks to appear below it. In-line elements appear within blocks of content, for example, you can add styling to text within a block by using the span element, and it won't bring the text 'out of line'.

Maccath
  • 3,936
  • 4
  • 28
  • 42
1

Span is an inline element, where a div is a block element.

wesside
  • 5,622
  • 5
  • 30
  • 35
1

div is display: block by default. span is display: inline by default. They may have different elements as their children. They may be children of different elements.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

For a start the div tag is a block level element and a span tag is an inline element.

https://developer.mozilla.org/en-US/docs/HTML/Block-level_elements

Dale
  • 10,384
  • 21
  • 34
0

A <span> is an inline element, where a <div> is a block element. I see them as basically the same with different default display styles. <div> defaults to display: block & <span> defaults to display: inline.

I tend to use <span> only then modify the display style as needed.