HTML Div

A div is a container that group or holds other elements. A div tag starts with <div> and ends with </div>

 

<div>
   <h2>I am inside the first div</h2>
</div>
<div>
   <p>I am a paragraph inside another div</p>
</div>
Output

I am inside the first div

I am a paragraph inside another div

A div can be inside another div and such will be called nested divs. Mostly, divs are used to layout components. For example, there will be a div for the navigation, another div for sidebar and another div for the contents. You can freely layout the divs using CSS (you can learn more about CSS on the CSS tutorial).

Share this tutorial!