HTML <div> Tag

The HTML <div> tag is a non-semantic tag that is used to define division in an HTML document. For example,

    <h2>This is a heading in a div element</h2>
    <p>This is some text in a div element.</p>

Browser Output

HTML div element  with some elements inside

Here, you can see the <div> tag is used like a container for HTML elements.

Usage of HTML <div>

The HTML <div> tag is generally used to group content and provide CSS styles using class or id attributes. For example,

<div class="div1">
    <h2>This is heading.</h2>
    <p>This is a paragraph</p>

<div class="div2">
    <h2>This is another heading.</h2>
    <p>This is another paragraph</p>

    .div1 {
        color: red;

    .div2 {
        color: green;

Browser Output

HTML div element styled with css

Here, the styling for the first two <div> comes from selector .div1 and .div2 respectively.

Table of Contents