November 21, 2026
What Is the HTML <div> Tag and How Is It Used?
Define a section or a part in an HTML file. A div element starts with <div> tag and ends with </div> element. You can provide different design and style to your div. A div can contain text, images, buttons, form etc.
| Attribute |
Description |
| id |
Through id attribute you can identify the div in your HTML file.
id="div_id"
|
| align |
We can set alignment with align attribute. Values are left, center and right. If you do not set align attribute of table then default alignment of remain is left.
align = 'left' Or align = 'center' Or align = 'right'
|
| Title |
Title attribute provides description about div, just like tooltip. Example of title attribute:
<div id="div_id" title="its my first div">
Div contents
</div>
|
| Class |
Through class attribute you can implement a CSS style class to your div element. Which can enhance our div's design and appearance.
<div class="CSS_class_name">
Div contents
</div>
|
| Style |
Through style attribute you can write CSS for your div element.
<div style="font-size:20px; color:#ff0000;">
Div contents
</div>
|
FAQ
1. What is the difference between class and id in a div tag?
The class attribute is used to identify one or more elements that share the same styling or behavior. The id attribute provides a unique identifier for a particular element within an HTML document.
2. Can I place one div tag inside another div tag?
Yes, placing one div element inside another is called nesting. Nested div elements help create complex webpage layouts by dividing content into smaller containers.
3. Is the div tag important for website layout?
Yes, the div element is commonly used to organize webpage layouts. When combined with CSS Flexbox or CSS Grid, it helps developers arrange content into columns, rows, cards, and other visual structures.