What is the difference between span and div?

Started by sirishasiri, January 08, 2018, 02:46:05 AM


kentowin

The <div> tag creates a line break and by default creates a division between the text that comes after the tag as begun and until the tag ends with </div>.

The <span> tag does not create a line break similar to a <div> tag, but rather allows the user to separate things from other elements around them on a page

Davidsmith0143

A span element is in-line and usually used for a small chunk of HTML inside a line. A div element is block-line and used to group a larger chunk of code.

esparkbiz

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.

Example of span class:

A <span> element used to color a part of a text:

<p>My mother has <span style="color:blue">blue</span> eyes.</p>

Output: 

My mother has blue eyes and my father has dark green eyes.

Example of div class:

A section in a document that will have a light blue background color:
<div style="background-color:lightblue">
<h3>This is a heading</h3>
<p>This is a paragraph</p>
</div>

Output:

This is some text.
This is a heading in a div element
This is some text in a div element.

This is some text.

Thank you... :)