HTML <div> tag

Updated: 10/11/2017 by Computer Hope

HTML div tagWhen writing in HTML, the <div> tag is a block element used to divide or section off content on a web page. It is useful for grouping block-level elements together so they can be formatted simultaneously using CSS. The following sections contain information about this tag including an example of it in use, as well as related attributes and browser compatibility.

Note: The <div> tag should only be used when there is not a more appropriate element, such as <nav> or <article>.

Example code

<div style="color:#ff9900; border-style:solid; border-width:2px;
  border-color:black;">
<h3>This content is in its own &lt;div&gt; element</h3>
<p>You can put any element into a div, which is excellent.</p>
</div>

Example result

This content is in its own <div> element

You can put any HTML element into a div, which is excellent.

Deprecated attributes

Within an HTML tag, an attribute dictates certain aspects of an HTML element. Attributes are made up of a name and value pair; all tags support standard attributes. Every attribute unique to the <div> tag is deprecated, meaning that it may function currently, but is not supported in going forward. In this case, CSS should be used in place of this attribute.

Attribute Description
align Designates the alignment of the content within a <div>

Compatibility

Internet Explorer Firefox Safari Opera Chrome
All versions All versions All version All versions All versions

Browser, Compatibility, Content, Image, Table, Text, Web design terms