HTML Cookbook Basic HTML Course

It's Easy!

Alternate version

The Div Tag

Div is short for division (or section), so it can be used to structure your page. Div is a large block-level element. You can put just about anything in a div, but you don't need to use it unless you want to manipulate your content, such as aligning or applying a class to some text.

Div can be used to separate sections of a page. You can put paragraphs in a div but you may not put a div in a paragraph. Div gains a lot of power with CSS and is essential for DHTML, so we'll talk about it more later.

Tag Form: <div>...</div>

Example: center an image (see image below)
<div align="center">
<img src="images/gnubee_mug.jpg" width="180" height="194" />
</div>
looks like:
mug

The center tag ( <center>...</center> ) was deprecated in HTML 4.01 and is not defined in XHTML Strict, so use the div tag instead from now on.

Example: alignment and style
<div align="right" style="color:red">
<p>This paragraph is red<br />and aligned to the right.</p>
</div>
looks like:

This paragraph is red
and aligned to the right.

Happy coding!
Gnubee

Links
Tips
Tools
References
Rules
HTML Help Gnubee - Newsgroup
HTML Course Contents (Home)

Valid XHTML 1.0!

Valid CSS!