English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML reference manual

HTML tag大全

HTML: <div> Tag

The HTML <div> tag defines a general container in an HTML document, which is usually used to group elements. This tag is also commonly referred to as the <div> element.

Online example

Three <div> tags were created in the document:

!doctype html
<html>
<head>
<meta charset="UTF-8">
<title>HTML5 div tag usage (Basic Tutorial Website oldtoolbag.com)</title>
<style>
.div_class{color:red}
#div_id{color:blue}
</style>
</head>
<body>
<div>
  <h2>The first Div</h2>
  <p>Text will appear in the Div section of the document</p>
</div>
<div class="div_class">
  <h2>The second Div with class applied</h2>
  <p>Text will appear in the Div section of the document</p>
</div>
<div id="div_id">
  <h2>The third Div with id applied</h2>
  <p>Text will appear in the Div section of the document</p>
</div>
</body>
</html>
Test to see ‹/›


In this HTML5In the document example, we created three <div> tags. The first <div> tag does not apply any class or ID. The second <div> tag applies a class named div_class to the <div> tag. The third <div> tag applies an ID named div_id to the <div> tag.

Browser compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the <div> tag.

Tag definition and usage instructions

The <div> tag is usually used to group elements together.

The <div> tag defines a section or an area within an HTML document.

The <div> tag is commonly used to group block-level elements, so that they can be formatted using CSS.

Tips and Notes

Tip:<div> elements are often used with CSS to layout web pages.

Note:By default, browsers usually place a line break before and after the <div> element. However, you can change this situation by using CSS.

HTML 4.01 and HTML5Differences between

HTML5 The align attribute is not supported in.

In HTML 4.01 In, the align attribute is deprecated.

Attribute

AttributeValueDescription
alignleft
right
center
justify
HTML5 Not Supported. HTML 4.01 Deprecated.    Specify the alignment of the content within a <div> element.

Global Attributes

Support for <div> tag Global Attributes of HTML.

Event Attributes

Support for <div> tag HTML Event Attributes.

Related Articles

HTML Tutorial:HTML Layout