DEV Community

Cover image for What is the difference between div and span?
Srijan
Srijan

Posted on • Originally published at hackinbits.com

Div vs Span What is the difference between div and span?

This post first appeared on hackinbits.com

<div> Element

<div> element is one of the famous block elements. It defines a section or division in an HTML document.<div> is a container element that is used to group the content, so that it can be styled easily using class or id attribute.

<div style="background-color:lightgrey">
  <h3> I am a heading </h3>
  <p> I am a paragraph </p>
</div>
Enter fullscreen mode Exit fullscreen mode

<span> Element

<span> element is one of the famous inline elements. It is an inline container element that is used to group inline elements in the HTML document. The grouped inline elements can then be easily styled using class or id attribute.

<p>You are reading about
  <span style="color:red"> Inline and Block Elements.</span>
</p>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)