HTML <div> tag

Updated: 09/12/2023 by Computer Hope
HTML div tag

When writing in HTML (hypertext markup language), 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 (cascading style sheets). When adding text to a <div> tag, if the text length is longer than the <div> width, the text automatically wraps to the next line.

The following sections contain information about this tag including an example of it in use, and 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 of <div> 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

All HTML tags support standard attributes that define the settings of an HTML element. In addition to the standard settings, the <div> tag had the following unique attributes that are now deprecated.

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

Compatibility

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

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