HTML <div> tag
The <div> tag is used to create a division or section or content that can exist as an independent element. It is mainly used for grouping multiple HTML elements. It might be the most common HTML block element.
Type: Block Element
Syntax of <div> tag
<div> Block level or inline level element. </div>
By default, the <div> does not render any visual style.
Supported Browsers
| Tag | Chrome | Internet Explorer | Firefox | Safari | Opera Mini |
|---|---|---|---|---|---|
| <div> | Yes | Yes | Yes | Yes | Yes |
Full code example
<!DOCTYPE html> <html> <head> <head> <head> <style> .container h3 { color: blue; } .container p { color: gray; } </style> </head> </head> </head> <body> <div class="container"> <h3>CSS</h3> <p> CSS is used to style the HTML document. </p> </div> </body> </html>
CSS
CSS is used to style the HTML document.
Attribute of <div> tag
| Attribute | Value | Define |
|---|---|---|
| align | left right center justify |
It defines the alignment of the contents within the <div> element. |
Note: The align attribute is obsolete in modern HTML. Now, it is completely replaced by CSS property.
Usage of <div> tag
It can be used in- grouping other HTML elements.
- creating page layouts.
- applying similar style to multiple elements using class attribute.
- making structural sections of a webpage.
More reference
The <div> element is the most commonly used HTML element. It is commonly styled using CSS properties and scripted using JavaScript. Since it is a block-level element, web browsers automatically render it on a new line with space before and after the element.
Default CSS property of <div> tag
div { display: block; }
