div element

If you don't know what an element is or how you must use it, I recommend you read the "HTML tags and attributes" tutorial that you can find in the HTML tutorials section.

Description

The div element is a generic container with no particular semantic meaning. It's commonly used in web authoring for styling purposes, in conjunction with the style and class attributes. It can also be helpful to provide common attributes for the elements contained by it, like for example lang or title.

Authors should consider div as a last resource, reserved only for cases when other more meaningful elements, like main, header, footer, nav or article don't apply.

Examples

The following example shows a couple of paragraphs (p element) wrapped with a div element. The purpose of div in this example, is to apply a set of styles to both paragraphs in one declaration.

<h1>Tim Berners-Lee</h1>
<div style="color: #040; font-style: italic">
  <p>Sir Timothy John "Tim" Berners-Lee, OM, KBE, FRS, FREng, FRSA, DFBCS (born 8 June 1955), also known as "TimBL", is an English computer scientist, best known as the inventor of the World Wide Web. He made a proposal for an information management system in March 1989, and he implemented the first successful communication between a Hypertext Transfer Protocol (HTTP) client and server via the Internet sometime around mid November of that same year.</p>
  <p>Berners-Lee is the director of the World Wide Web Consortium (W3C), which oversees the Web's continued development. He is also the founder of the World Wide Web Foundation, and is a senior researcher and holder of the Founders Chair at the MIT Computer Science and Artificial Intelligence Laboratory (CSAIL). He is a director of the Web Science Research Initiative (WSRI), and a member of the advisory board of the MIT Center for Collective Intelligence.</p>
</div>

Tim Berners-Lee

Sir Timothy John "Tim" Berners-Lee, OM, KBE, FRS, FREng, FRSA, DFBCS (born 8 June 1955), also known as "TimBL", is an English computer scientist, best known as the inventor of the World Wide Web. He made a proposal for an information management system in March 1989, and he implemented the first successful communication between a Hypertext Transfer Protocol (HTTP) client and server via the Internet sometime around mid November of that same year.

Berners-Lee is the director of the World Wide Web Consortium (W3C), which oversees the Web's continued development. He is also the founder of the World Wide Web Foundation, and is a senior researcher and holder of the Founders Chair at the MIT Computer Science and Artificial Intelligence Laboratory (CSAIL). He is a director of the Web Science Research Initiative (WSRI), and a member of the advisory board of the MIT Center for Collective Intelligence.

Now, a title attribute is applied to a group of elements, by wrapping them with a div and setting the attribute there. In most browsers you'll see the contents of the title attribute by placing you mouse pointer over any element in the group.

<h1>The World Wide Web</h1>
<div title="Initial description of the World Wide Web">
  <p>The World Wide Web (abbreviated as WWW or W3, commonly known as the Web) is a system of interlinked hypertext documents that are accessed via the Internet.</p>
  <p>With a web browser, one can view web pages that may contain text, images, videos, and other multimedia and navigate between them via hyperlinks.</p>
</div>

The World Wide Web

The World Wide Web (abbreviated as WWW or W3, commonly known as the Web) is a system of interlinked hypertext documents that are accessed via the Internet.

With a web browser, one can view web pages that may contain text, images, videos, and other multimedia and navigate between them via hyperlinks.

Attributes

Specific attributes

align

The horizontal alignment of the text inside this element and all of its children. There are four possible values (case-insensitive):

  • left: text is aligned to the left margin.
  • center: text is centered.
  • right: text is aligned to the right margin.
  • justify: text is justified or aligned to both margins.

This attribute has become obsolete in HTML and, therefore, its use is no longer valid. Authors should replace it with style sheets declarations.

Example

<div align="center">The only source of knowledge is experience</div>

Global attributes

For information about global attributes refer to this list of global attributes in HTML5.

Events

Global events

For information about global events refer to this list of global events in HTML5.