Basic difference between div and span

Share

demo

The basic difference between them is ,div is block level element and span is inline level element. Most of us do not know what is block level and inline level elements.

As their name implies , block level elements make their presence like a block , like a photo frame, whereas inline element make their presence like a chain, one by one.

This can be illustrated more by HTML example. Suppose we have two divs and two spans in following orders:

This is block one
This is block two

This is inline element one This is inline element two

And their CSS as :

div{border:1px solid #000; padding:10px;}
span{border:1px solid #000; padding:10px;}

Here is the output:

demo

You will notice that div elements are coming in a row, in other words automatic break is inserted. Whereas in case of span elements all are coming one after the other without any breaks.

    Tips:

  • Inline elements does not take margin from top and bottom unless you change them into block level element.
  • You can change inline element into block level element through CSS and vise-versa. That is :
  • div{display:inline}
    span{display:block}
    

Thats all!!

Cheers!

  • December 16, 2009
8 Best Free Stock Video Websites for Tiktok, Reels, and Shorts Top 5 PHP Frameworks: Fast and Secure