Little Web Hut

HTML 4.01 and XHTML 1.0 Reference: <col> Tag

HTML <col> Tag - Table Column
Syntax HTML syntax - This element does not require a closing tag.
<col>

XHTML syntax - This element is opened and closed, within a single tag, by adding a space followed by a forward slash at the end of the tag.
<col />
Usage The <col> tag is used to specify column attributes within a table. If used, place the <col> tag before any <thead>, <tfoot>, <tbody>, or <tr> tags within the table. Also, if a <caption> tag is used, the <col> tag should occur after it.

A table can contain a separate <col> tag for each column. Using the span attribute, a single <col> tag can apply to more than one column.

HTML Example using one <col> tag for each column.
<table border="1">
 <caption>Stock Tracker</caption>
 <col width="200">
 <col width="300">
 <tr>
  <th>Stock Symbol</th>
  <th>Profit</th>
 </tr>
 <tr>
  <td>MSFT</td>
  <td>$723.48</td>
 </tr>
 <tr>
  <td>GOOG</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It HTML Style

XHTML Example using one <col> tag for each column.
<table border="1">
 <caption>Stock Tracker</caption>
 <col width="200" />
 <col width="300" />
 <tr>
  <th>Stock Symbol</th>
  <th>Profit</th>
 </tr>
 <tr>
  <td>MSFT</td>
  <td>$723.48</td>
 </tr>
 <tr>
  <td>GOOG</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It XHTML Style

Content Model The <col> element cannot contain any tags.

<col> Tag Attribute Summary
Required Tag Specific Core Focus Events Language
  align char charoff span valign width id class style title   onclick ondblclick onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup dir lang xml:lang1
Notes: 1. XHTML only.

<col> Tag Attributes
Attribute Description
alignThe align attribute specifies the horizontal alignment within a cell. Possible values are "center", "char", "justify", "left", and "right".
charThe char attribute specifies a single character to act as an alignment character when the align attribute is set to "char". The default character for this attribute is the decimal point.

Note: This attribute may have little or no browser support among popular browsers.
charoffThe charoff attribute specifies an offset to the first occurrence of the alignment character, which is specified by the char attribute.

Note: This attribute may have little or no browser support among popular browsers.
spanThe span attribute specifies the number of columns that the <col> tag applies to.

HTML Example using a single <col> tag for multiple columns by using the span attribute.
 <col span="2" width="200">
Test It HTML Style

XHTML Example using a single <col> tag for multiple columns by using the span attribute.
 <col span="2" width="200" />
Test It XHTML Style

valignThe valign attribute specifies the vertical alignment within a cell. Possible values are "baseline", "bottom", "middle", and "top".
widthThe width attribute specifies the default column width. The value of the width attribute can be specified in pixels, percentage, or relative size.

HTML <col> tag example using pixels:
<col width="300">

HTML <col> tag example using percentage:
<col width="30%">

HTML <col> tag example using relative size:
<col width="2*">

HTML <col> tag example using relative size to set the width to match the column's contents:
<col width="0*">


XHTML <col> tag example using pixels:
<col width="300" />

XHTML <col> tag example using percentage:
<col width="30%" />

XHTML <col> tag example using relative size:
<col width="2*" />

XHTML <col> tag example using relative size to set the width to match the column's contents:
<col width="0*" />
idThe id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. See id Example
classThe class attribute assigns a class name to a tag. The class name does not need to be unique. More than one tag can have the same class name. This allows style sheets or scripts to reference multiple tags with a single class name. See class Example
styleThe style attribute specifies styles for the tag. For Cascading Style Sheets (CSS), the syntax is name:value. Each name:value pair is separated by semicolons. See style Example
titleThe title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. See title Example
onclickThe onclick attribute specifies a script to be run when the object is clicked with a mouse or other pointing device. See onclick Example
ondblclickThe ondblclick attribute specifies a script to be run when the object is double clicked with a mouse or other pointing device. See ondblclick Example
onkeydownThe onkeydown attribute specifies a script to be run when a key is pressed down. See onkeydown Example
onkeypressThe onkeypress attribute specifies a script to be run when a key is pressed and released. See onkeypress Example
onkeyupThe onkeyup attribute specifies a script to be run when a key is released. See onkeyup Example
onmousedownThe onmousedown attribute specifies a script to be run when the mouse button, or other pointing device button, is pressed while over the object. See onmousedown Example
onmousemoveThe onmousemove attribute specifies a script to be run when the mouse, or other pointing device, is moved while it is over the object. See onmousemove Example
onmouseoutThe onmouseout attribute specifies a script to be run when the mouse, or other pointing device, is moved away from an object after being over it. See onmouseout Example
onmouseoverThe onmouseover attribute specifies a script to be run when the mouse, or other pointing device, is moved onto the object. See onmouseover Example
onmouseupThe onmouseup attribute specifies a script to be run when the mouse button, or other pointing device button, is released while over the object. See onmouseup Example
dirThe dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. See dir Example
langThe lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See lang Example
xml:langThe xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See xml:lang Example

Note: XHTML only.

HTML <col> Tag Examples
Test It HTML StyleTest It HTML StyleExample using one <col> tag for each column.
Test It HTML StyleTest It HTML StyleExample using a single <col> tag for multiple columns by using the span attribute.