HTML <div> tagS2C Home   « HTML <div> tag

Definition

The <div> tag doesn't affect our web page directly but is generally used to group blocks of HTML together for styling with CSS.

Example


<div style="font-style:italic;">
  <h2>The Div Tag Group Blocks of HTML Together for Styling</h2>
  <p>The Colours of the Rainbow are:</p>
   <ol>
     <li><span style="color:red;">Red</span></li>
     <li><span style="color:orange;">Orange</span></li>
     <li><span style="color:yellow;">Yellow</span></li>
     <li><span style="color:green;">Green</span></li>
     <li><span style="color:blue;">Blue</span></li>
     <li><span style="color:indigo;">Indigo</span></li>
     <li><span style="color:violet;">Violet</span></li>
   </ol>
</div>

Required Attributes

NONE

Optional Attributes

NONE

Common Attributes

class - specifies a classname for the element allowing you to apply the style of the predefined class to the content.


<div class="classname"></div>

id - specifies a unique id for the element allowing you to apply the style of the predefined id to the content.


<div id="idname"></div>

style - specifies an inline style for the element allowing you to apply the style to the content.


<div style="color:red;text-align:left"></div>

title - specifies extra information about the content.


<div title="information about the content"></div>

Language Attributes

dir - specifies the directional flow of the content.


<div dir="ltr"></div>   <!-- The text will flow from left to right -->

<div dir="rtl"></div>   <!-- The text will flow from right to left -->

lang - specifies a language code for the content of the element.


<div lang="en"></div>

xml:lang - specifies a language code for the content of the element in XHTML documents.


<div xml:lang="fr"><div>

Document Event Attributes

NONE

Form Event Attributes

NONE

Image Event Attributes

NONE

Keyboard Event Attributes

onkeydown - The JavaScript code to be run when an element is in focus and keyboard key is pressed.


<div onkeydown="go()"></div>   <!-- Executes the go() function -->

onkeypress - The JavaScript code to be run when an element is in focus and keyboard key is pressed down and released.


<div onkeypress="go()"></div>   <!-- Executes the go() function -->

onkeyup - The JavaScript code to be run when an element is in focus and keyboard key is released.


<div onkeyup="go()"></div>   <!-- Executes the go() function -->

Mouse Event Attributes

onclick - The JavaScript code to be run when a mouse is clicked on the element.


<div onclick="go()"></div>   <!-- Executes the go() function -->

ondblclick - The JavaScript code to be run when a mouse is double clicked on the element.


<div ondblclick="go()"></div>   <!-- Executes the go() function -->

onmousedown - The JavaScript code to be run when the mouse button is pressed down while the cursor is over the element.


<div onmousedown="go()"></div>   <!-- Executes the go() function -->

onmousemove - The JavaScript code to be run when the mouse button is moved.


<div onmousemove="go()"></div>   <!-- Executes the go() function -->

onmouseout - The JavaScript code to be run when the mouse cursor moves off an element.


<div onmouseout="go()"></div>   <!-- Executes the go() function -->

onmouseover - The JavaScript code to be run when the mouse cursor moves over an element.


<div onmouseover="go()"></div>   <!-- Executes the go() function -->

onmouseup - The JavaScript code to be run when the mouse button is released while the cursor is over the element.


<div onmouseup="go()"></div>   <!-- Executes the go() function -->

go to home page Homepage go to top of page Top