Description
The HTML element <div>
(short form of division) is used to define a division or section in an HTML document.
It is used as a generic container for HTML elements, which has no meaning or default rendering.
It is commonly used to define different sections of an HTML document, which can be easily styled using CSS.
NOTE: As the element <div>
doesn't have any meaning or default rendering, it is the ideal element to group related elements and apply styles using id
or class
attributes.
The below table summarizes its usage.
Usage Details | |
Placement | It is displayed as a Block element. |
Contents | It can contain Block elements, Inline elements, and text. |
Tags | Both opening and closing tags are required. |
Versions | HTML 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <div>
element.
<div>...</div>
Examples
In the below example, the <div>
element is used to group the elements used to build a post.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h1>HTML Element - div</h1>
<div class="post">
<h1>Post Title</h1>
<p>Post description goes here.</p>
</dialog>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <div>
tag.
Attribute Type | Details |
Element-Specific Attributes | The tag <div> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <div> supports the HTML Global Attributes. |
Event Attributes | The tag <div> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <div>
element.
Attribute | Value | Description |
align | left, right, center, justify | Obsolete - Not to use. Specifies the alignment of the div content. |
Browser Compatibility
The tag <div>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 4+