HTML <div> Tag

Example

A section in a document that will have a light blue background color:

<div style=”background-color:lightblue”>
<h3>This is a heading</h3>
<p>This is a paragraph.</p>
</div>

Try it Yourself »


Definition and Usage

The <div> tag defines a division or a section in an HTML document.

The <div> element is often used as a container for other HTML elements to style them with CSS or to perform certain tasks with JavaScript.


Browser Support

Element
<div> Yes Yes Yes Yes Yes

Tips and Notes

Tip: The <div> element is very often used together with CSS, to layout a web page.

Note: By default, browsers always place a line break before and after the <div> element. However, this can be changed with CSS.


Differences Between HTML 4.01 and HTML5

The align attribute not supported in HTML5.


Attributes

Attribute Value Description
align left
right
center
justify
Not supported in HTML5.
Specifies the alignment of the content inside a <div> element

Global Attributes

The <div> tag also supports the Global Attributes in HTML.


Event Attributes

The <div> tag also supports the Event Attributes in HTML.


Related Pages

HTML tutorial: HTML Blocks

HTML tutorial: HTML Layout

HTML DOM reference: Div Object


Default CSS Settings

Most browsers will display the <div> element with the following default values:

Example

div {
display: block;
}

Try it Yourself »

HTML <div> align Attribute

Example

A section in a document that will be center-aligned:

<div align=”center”>
This is some text!
</div>

Try it Yourself »


Definition and Usage

The align attribute specifies the horizontal alignment of the content inside a <div> element.


Browser Support

Attribute
align Yes Yes Yes Yes Yes

Compatibility Notes

The <div> align attribute is not supported in HTML5. Use CSS instead.

CSS syntax: <div style=”text-align:center”>

CSS Example: Align text in a <div> element

In our CSS tutorial you can find more details about the text-align property.


Syntax

<div align=”left|right|center|justify”>

Attribute Values

Value Description
left Left-align content
right Right-align content
center Center-align content
justify Stretches the lines so that each line has equal width (like in newspapers and magazines)

Post Author: Zahid Farid