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
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.