Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

The DIV Tag

By Jennifer Kyrnin, About.com

Description of the DIV Tag:

The <div> tag in XHTML is a tag that defines logical divisions within the content of a page. What this means is that a <div> tag defines sections of a Web page to make it easier to manage, style, and manipulate. You can use the <div> tag when you want to center a block of content or position a content block on the page. The <div> tag is a very powerful tool for Web developers.

HTML Definition of the DIV Tag:

In order to use the <div> tag you need to know the HTML definition of the <div> tag. Some key tips:

  • The <div> tag is a block-level element
  • The <div> tag can contain nearly any other tag
  • The <div> tag cannot be inside <p> tags

Tips for Using the DIV Tag:

  • The <div> tag is not a replacement <p> tag. The <p> tag is for paragraphs, only, while the <div> tag defines more general divisions within a document. Don't replace <p> tags with <div> tags.
  • It's a good idea to label your <div> tags as you place them in your document. For example, if you're defining the main content area of your site, you should name that DIV tag: "maincontent". <div id="maincontent">
  • It's always a good idea to close your <div> tags as soon as you open them. Then place the contents within the element.
  • If you nest your <div> tags, be sure that you know where your content is going (in other words, which DIV it should be part of).

Explore Web Design / HTML

About.com Special Features

Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. HTML and XHTML
  5. XHTML
  6. HTML Tags
  7. The DIV Tag

©2009 About.com, a part of The New York Times Company.

All rights reserved.