HTML » Tags » div

Version: 3.2, 4.0

Compability: Explorer 4, 5  Netscape 6

Syntax:
<div> ... </div>

The <div> tag is used to designate a block-line portion of an HTML document as a div element and to apply any of the core attributes of this tag against the contents of that element. The behavior of this tag is block-line, because this tag causes a line break (the equivalent of a br tag) to occur both before and after the div element. div tags, which can be nested, allow a significant degree of control and manipulation of each individual block section of your web page.

For example, you could use the class or style core attributes to apply the effects of Cascading Style Sheets, or you could use the lang attribute to display a foreign language text, or you could assign an id to each block of code for reference by a hyperlink.
 
In contrast, you should use the span tag when you want to apply attributes to an inline portion of a page. Note that the behavior of the span tag is not block-line, but rather inline, since the effects occur in the normal flow of the text and images (without the tag inserting any additional linefeeds or carriage returns).
 
With the advent of Cascading Style Sheets, both the div and span tags have gained importance and usefulness.
 
The ending tag is optional. However, it is recommended that it be included.
 

Examples

Code:
<div style="text-align: left;" id="div_example1">
The <b>div</b> offers exciting possibilities for the developer.
</div>
<div style="text-align: center;" id="div_example2">
You should take time to learn about this tag.
</div>
<div style="text-align: right;" id="div_example3">
Also check out the <b>span</b> tag.
</div>
Output:
The div offers exciting possibilities for the developer.
You should take time to learn about this tag.
Also check out the span tag.
Language(s): HTML

See Also: