Copyright ©

HTML <div> tag



The HTML <div> tag is used for defining a section of your document. With the div tag, you can group large sections of HTML elements together and format them with CSS.

The difference between the div tag and the span tag is that the div tag is used with block-level elements whilst the span tag is used with inline elements.

Difference between HTML and XHTML:

The align attribute of <div> is deprecated in HTML as well as in XHTML.


<div style="background-color:orange;text-align:center">
  <p>Navigation section</p>
<div style="border:1px solid black;text-align:right ">
  <p>Content section</p>

This will produce following result:

Navigation section

Content section

Online Practice:

To Become more comfortable - Do Online Practice


Deprecated Defines alignment of the content enclosed in div tag.

Standard Attributes:

classDocument wide identifier
dirSpecifies the direction of the text
idDocument wide identifier
titleSpecifies a title to associate with the element.
styleHelps to include inline casecadubf style sheet.
langSets the language code.

Event Attributes:

onclickScript runs when a mouse click
ondblclickScript runs when a mouse double-click
onmousedownScript runs when mouse button is pressed
onmouseupScript runs when mouse button is released
onmouseoverScript runs when mouse pointer moves over an element
onmousemoveScript runs when mouse pointer moves
onmouseoutScript runs when mouse pointer moves out of an element
onkeypressScript runs when key is pressed and released
onkeydownScript runs when key is pressed
onkeyupScript runs when key is released

Copyright ©