Lesson 13 of 21 – HTML Div
62%

HTML Div

The <div> element is used as a container for other HTML elements.

Definition: The <div> element is a block-level container used to group HTML elements together.

The <div> Element

The <div> element is by default a block-level element, meaning that it takes all available width and starts on a new line.

<div> as a Container

The <div> element is often used to group sections of a web page together.

Example
<div>
   <h2>London</h2>
   <p>London is the capital city of England.</p>
   <p>London has over 13 million inhabitants.</p>
</div>

Multiple <div> Elements

You can have many <div> containers on the same page.

Example
<div>
   <h2>Patna</h2>
   <p>Patna is the capital city of Bihar.</p>
</div>

<div>
   <h2>Delhi</h2>
   <p>Delhi is the capital city of India.</p>
</div>

<div>
   <h2>Aurangabad</h2>
   <p>Aurangabad is located in Bihar.</p>
</div>

Using Class with Div

Classes are commonly used with div elements for styling.

Example
<div class="box">
   Welcome to Soopro Pathshala
</div>

Using ID with Div

IDs uniquely identify a div element.

Example
<div id="header">
   Website Header
</div>

Key Points about HTML Div

  • <div> is a block-level element.
  • Used as a generic container.
  • Helps organize webpage content.
  • Used with CSS for styling and layouts.
  • Works with JavaScript for dynamic content.
  • Supports class and id attributes.
  • Can contain text, images, forms, tables, and other HTML elements.
  • Useful for creating sections on a webpage.

🧠 Quiz

Which HTML tag is commonly used as a container for other elements?