Using the DIV Element

In HTML 4, the DIV element is a block element used to designate a division within a document. Otherwise, the DIV element has no formatting characteristics, although the deprecated ALIGN attribute can be used to center or right-align its content. From the start, the DIV element was intended to take any formatting characteristics from styles.

By nesting other elements within a DIV element, any styles applied to the DIV element also impact those nested elements. In the following example, a DIV rule is added to the style sheet, set to be displayed with a border, background image, and other formatting characteristics:

 div { font-family: Verdana, Arial, sans-serif; font-size: 1.1em; color: #ffff99; background: navy url(dark.jpg); ...

Get Cascading Style Sheets (CSS) by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.