W3Schools.com (2024)


Example

A <div> section in a document that is styled with CSS:

<html>
<head>
<style>
.myDiv {
border: 5px outset red;
background-color: lightblue;
text-align: center;
}
</style>
</head>
<body>

<div class="myDiv">
<h2>This is a heading in a div element</h2>
<p>This is some text in a div element.</p>
</div>

</body>
</html>

Try it Yourself »

More "Try it Yourself" examples below.

Definition and Usage

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

The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript.

The <div> tag is easily styled by using the class or id attribute.

Any sort of content can be put inside the <div> tag!

Note: By default, browsers always place a line break before and after the <div> element.

Browser Support

Element
<div> Yes Yes Yes Yes Yes

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 Block and Inline Elements

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 »


W3schools Pathfinder

Track your progress - it's free!

W3Schools.com (2024)

References

Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 6115

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.