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

Definition

The <div> tag doesn't affect our web page directly but is generally used to group block-level content for attribution or styling with CSS.

For attribution or CSS styling of inline content use the <span> tag instead.

Use the <article>, <aside>, <nav> and <section> elements where appropriate in HTML5 rather than the <div> element which would have been used in HTML4.

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>

The Div Tag Group Blocks of HTML Together for Styling

The Colours of the Rainbow are:

  1. Red
  2. Orange
  3. Yellow
  4. Green
  5. Blue
  6. Indigo
  7. Violet

Attributes

The following attributes can be used with the <div> tag.


<div> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <div> tag.
<div> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<div class="name">Divisional Content</div>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<div id="name">Divisional Content</div>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<div style="color:red;">Divisional Content</div>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<div title="Content info">Divisional Content</div>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<div accesskey="a">Divisional Content</div>
tabindexSpecifies a tab order for the element.

<div tabindex="1">Divisional Content</div>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<div dir="ltr">Divisional Content</div>
<!-- The text will flow from right to left -->
<div dir="rtl">Divisional Content</div>
langSpecifies a language code for the content of the element.

<div lang="en">Divisional Content</div>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<div spellcheck="true">Divisional Content</div> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<div translate="no">Divisional Content</div> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<div contenteditable="true">Divisional Content</div> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<div draggable="true">Divisional Content</div>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<div hidden>Divisional Content</div> 
<div hidden="hidden">Divisional Content</div> 
<div> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<div oncopy="go()">Divisional Content</div> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<div oncut="go()">Divisional Content</div>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<div onpaste="go()">Divisional Content</div>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<div ondrag="go()">Divisional Content</div>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<div ondragend="go()">Divisional Content</div>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<div ondragenter="go()">Divisional Content</div>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<div ondragleave="go()">Divisional Content</div>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<div ondragover="go()">Divisional Content</div>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<div ondragstart="go()">Divisional Content</div>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<div ondrop="go()">Divisional Content</div>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<div onblur="go()">Divisional Content</div>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<div onchange="go()">Divisional Content</div>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<div oncontextmenu="go()">Divisional Content</div>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<div onfocus="go()">Divisional Content</div>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<div oninput="go()">Divisional Content</div>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<div oninvalid="go()">Divisional Content</div>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<div onreset="go()">Divisional Content</div>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<div onselect="go()">Divisional Content</div>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<div onsubmit="go()">Divisional Content</div>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<div onkeydown="go()">Divisional Content</div>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<div onkeypress="go()">Divisional Content</div>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<div onkeyup="go()">Divisional Content</div>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<div onabort="go()">Divisional Content</div>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<div oncanplay="go()">Divisional Content</div>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<div oncanplaythrough="go()">Divisional Content</div>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<div oncuechange="go()">Divisional Content</div>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<div ondurationchange="go()">Divisional Content</div>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<div onemptied="go()">Divisional Content</div>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<div onended="go()">Divisional Content</div>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<div onloadeddata="go()">Divisional Content</div>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<div onloadedmetadata="go()">Divisional Content</div>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<div onloadstart="go()">Divisional Content</div>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<div onpause="go()">Divisional Content</div>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<div onplay="go()">Divisional Content</div>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<div onplaying="go()">Divisional Content</div>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<div onprogress="go()">Divisional Content</div>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<div onratechange="go()">Divisional Content</div>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<div onseeked="go()">Divisional Content</div>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<div onseeking="go()">Divisional Content</div>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<div onstalled="go()">Divisional Content</div>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<div onsuspend="go()">Divisional Content</div>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<div ontimeupdate="go()">Divisional Content</div>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<div onvolumechange="go()">Divisional Content</div>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<div onwaiting="go()">Divisional Content</div>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<div onclick="go()">Divisional Content</div>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<div ondblclick="go()">Divisional Content</div>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<div onmousedown="go()">Divisional Content</div>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<div onmousemove="go()">Divisional Content</div>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<div onmouseout="go()">Divisional Content</div>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<div onmouseover="go()">Divisional Content</div>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<div onmouseup="go()">Divisional Content</div>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<div onwheel="go()">Divisional Content</div>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<div onscroll="go()">Divisional Content</div> 
Window - NONE