HTML <colgroup> tagS2C Home   « HTML <colgroup> tag

Definition

The <colgroup> tag is used for defining a group of columns in a table and is also used as a container for one or more <col> elements.

The <colgroup> element must follow any <caption> element and precede any <thead>, <tbody>, <tfoot> or <tr> elements.

The <colgroup> element must either have child <col> element(s) or be used in conjunction with the span attribute, whose value must be a valid non-negative integer greater than zero and less than or equal to 1000.

The use of the span attribute is mutually exclusive when using the <col> and <colgroup> elements together.

When styling individual columns use the <col> element instead.

Example


<table>
  <colgroup style="border:1px solid black;">
    <col span="2" style="background-color:purple;border:1px solid white;">
    <col style="background-color:yellow;">
  </colgroup>
  <tr>
    <th>Fruit</th>
    <th>Colour</th>
    <th>Quantity</th>
  </tr>
  <tr>
    <td>Banana</td>
    <td>Yellow</td>
    <td>5</td>
  </tr>
  <tr>
    <td>Pea</td>
    <td>Green</td>
    <td>50</td>
  </tr>
</table>
Fruit Colour Quantity
Banana Yellow 5
Pea Green 50

Attributes

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


<colgroup> Specific Attributes
Attribute Value Description Example
spanNon-negative integerSpecifies the number of columns - must be greater than zero.

<colgroup span="2">
<colgroup> 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.

<colgroup class="name">Column group contents</colgroup>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<colgroup id="name">Column group contents</colgroup>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<colgroup style="color:red;">Column group contents</colgroup>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<colgroup title="Content info">Column group contents</colgroup>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<colgroup accesskey="a">Column group contents</colgroup>
tabindexSpecifies a tab order for the element.

<colgroup tabindex="1">Column group contents</colgroup>
Language
dirSpecifies the directional flow of the content.

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

<colgroup lang="en">Column group contents</colgroup>
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. -->
<colgroup spellcheck="true">Column group contents</colgroup> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<colgroup translate="no">Column group contents</colgroup> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<colgroup contenteditable="true">Column group contents</colgroup> 
draggableSpecifies whether the element is draggable.

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

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

 <!-- Executes go() function -->
<colgroup oncopy="go()">Column group contents</colgroup> 
oncutThe script to be run when the user cuts the content of an element.

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

 <!-- Executes go() function -->
<colgroup onpaste="go()">Column group contents</colgroup>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<colgroup ondrag="go()">Column group contents</colgroup>
ondragendThe script to be run when an element has stopped being dragged.

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

 <!-- Executes go() function -->
<colgroup ondragenter="go()">Column group contents</colgroup>
ondragleaveThe script to be run when an element leaves a valid drop target.

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

 <!-- Executes go() function -->
<colgroup ondragover="go()">Column group contents</colgroup>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<colgroup ondragstart="go()">Column group contents</colgroup>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<colgroup ondrop="go()">Column group contents</colgroup>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<colgroup onblur="go()">Column group contents</colgroup>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<colgroup onchange="go()">Column group contents</colgroup>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<colgroup oncontextmenu="go()">Column group contents</colgroup>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<colgroup onfocus="go()">Column group contents</colgroup>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<colgroup oninput="go()">Column group contents</colgroup>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<colgroup oninvalid="go()">Column group contents</colgroup>
onresetThe script to be run when a dragged element is being dropped.

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

 <!-- Executes go() function -->
<colgroup onselect="go()">Column group contents</colgroup>
onsubmitThe script to be run when a form is submitted.

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

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

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

 <!-- Executes go() function -->
<colgroup onkeyup="go()">Column group contents</colgroup>
Media
onabortThe script code to be run on abort.

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

 <!-- Executes go() function -->
<colgroup oncanplay="go()">Column group contents</colgroup>
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 -->
<colgroup oncanplaythrough="go()">Column group contents</colgroup>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<colgroup oncuechange="go()">Column group contents</colgroup>
ondurationchangeThe script to be run when the length of the media is changed.

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

 <!-- Executes go() function -->
<colgroup onemptied="go()">Column group contents</colgroup>
onendedThe script to be run when the media has reach the end.

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

 <!-- Executes go() function -->
<colgroup onloadeddata="go()">Column group contents</colgroup>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<colgroup onloadedmetadata="go()">Column group contents</colgroup>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<colgroup onloadstart="go()">Column group contents</colgroup>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<colgroup onpause="go()">Column group contents</colgroup>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<colgroup onplay="go()">Column group contents</colgroup>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<colgroup onplaying="go()">Column group contents</colgroup>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<colgroup onprogress="go()">Column group contents</colgroup>
onratechangeThe script to be run when the playback rate changes.

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

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

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

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

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

 <!-- Executes go() function -->
<colgroup ontimeupdate="go()">Column group contents</colgroup>
onvolumechangeThe script to be run when the volume has changed or been muted.

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

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

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

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

 <!-- Executes go() function -->
<colgroup onmousedown="go()">Column group contents</colgroup>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<colgroup onmousemove="go()">Column group contents</colgroup>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<colgroup onmouseout="go()">Column group contents</colgroup>
onmouseoverThe script to be run when the mouse cursor moves over an element.

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

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

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

 <!-- Executes go() function -->
<colgroup onscroll="go()">Column group contents</colgroup> 
Window - NONE

Relevant HTML Tutorials

HTML Advanced - Advanced Tables