<col> (Column)
This element defines a column within a table and is used for grouping and alignment purposes. It generally is found within a <colgroup> element.
Standard Syntax
<col
align="center | char | justify | left | right"
char="character"
charoff="number"
class="class name(s)"
dir="ltr | rtl"
id="unique alphanumeric identifier"
lang="language code"
span="number"
style="style information"
title="advisory text"
valign="baseline | bottom | middle | top"
width="column width specification" />
Attributes Defined by Internet Explorer
bgcolor="color name | #RRGGBB" (5.5)
Standard Events
onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
Events Defined by Internet Explorer
onlayoutcomplete, onreadystatechange
Element Specific Attributes
- align
- This attribute specifies horizontal alignment of a cell's contents.
- bgcolor
- Applies a background color to all cells in the column (IE 5.5 only).
- char
- This attribute is used to set the character to align the cells in a column on. Typical values for this include a period (.) when attempting to align numbers or monetary values.
- charoff
- This attribute is used to indicate the number of characters to offset the column data from the alignment characters specified by the char value.
- span
- When present, this attribute applies the attributes of the <col> element to additional consecutive columns.
- valign
- This attribute specifies the vertical alignment of the text within the cell. Possible values for this attribute are baseline, bottom, middle, and top.
- width
- This attribute specifies a default width for each column in the current column group. In addition to the standard pixel and percentage values, this attribute might take the special form 0*, which means that the width of each column in the group should be the minimum width necessary to hold the column's contents. Relative widths such as 0.5* also can be used.
Example
<table border="1" width="400">
<colgroup>
<col align="center"width="150" />
<col align="right" />
</colgroup>
<td>This column is aligned to the center.</td>
<td>This one is aligned to the right.</td>
<tr>
<td>!</td>
<td>?</td>
</tr>
<tr>
<td>!</td>
<td>?</td>
</tr>
</table>
Compatibility
HTML 4, 4.01, XHTML 1.0, 1.1, Basic
Internet Explorer 4, 5, 5.5, 6
Netscape 6, 7 Opera 7
Notes
Under XHTML 1.0, <col> requires a trailing slash: <col />.
This element should appear within a colgroup element, and like that element, it is somewhat of a convenience feature used to set attributes with one or more table columns. In practice, few developers seem to use it.