Div & Span

The Div Tag

The div tag is an HTML tag which is often used in CSS to divide different sections of a web page. It is often used when styling a group of elements (you pretty much use it with ID’s and classes).

As an example, to demonstrate the use of div tag:

Style.CSS

.custom
{
   color: purple;
   text-decoration: underline;
}

Your Webpage

<div class="custom">
    <h4> This is a paragraph </h4>
    <h5> This is another paragraph </h5>
    <p> This is a next paragraph </p>
</div>

Div tags are particularly useful when you are creating the layout of a website. In the simple example above it is used to style the elements contained within it to have a purple color.

The Span Tag

The span tag is also an HTML tag but unlike the div, it is used to apply a style in-line rather than to a group of elements.

<p> This is a <span class="edit"> paragraph </span> </p>