HTML <div> tag

The <div> tag is used to set apart a section of a wepage. With the <div> tag you can group together a set of related elements like some links and and an image for the page menu, or headings and a few paragraphs for the page content.

Be sure to read our HTML div & span tags tutorial which goes into more detail about grouping content, the <div> tag, and its related tag <span>.

NOTE: The browser will automatically place a line break before and after a div element.

Attributes

Attribute Possible values Description
align left, right, center, justify Deprecated. Specifies how content in a div element will be aligned

Standard attributes

class, dir, id, lang, style, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

onclick, ondblclick, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onkeydown, onkeypress, onkeyup

For more information on event attributes, check out our HTML event attributes reference page.

Example

<div style="background: #ddd; font-family: tahoma; text-align: center; line-height: 1.7em;"> <a href="#">Home</a> | <a href="#">About Us</a> | <a href="#">FAQ</a> | <a href="#">Contact Us</a> </div> <div style="background: #f9f9f4; font-size: 16px; height: 210px; padding-left: 10px;"> Welcome to the webpage of webpages! This is it, you have reached it! Now read it again and again! </div>
Output:
Home | About Us | FAQ | Contact Us
Welcome to the webpage of webpages! This is it, you have reached it! Now read it again and again!

Tips & notes

Use <div> together with CSS to layout the contents of a webpage. Read our HTML div & span tags tutorial for details on this.

Use CSS to set styles for div elements (as well as the elements within them). You can do things like set the background color, borders, make div's float to the left or right of a page, change text size, and much more.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation