<COL>NN n/a   IE 3   HTML 4
<COL>End Tag: Forbidden
 

The COL element provides shortcuts to assigning widths and other characteristics (styles) to one or more subsets of columns within a table or within a table's column group. With this information appearing early in the TABLE element, a browser equipped to do so starts rendering the table before all source code for the table has loaded (at which time it would otherwise perform all of its geographical calculations).

You can use the COL element in combination with the COLGROUP element or by itself. The structure depends on how you need to assign widths and styles to individual columns or contiguous columns. A COL element can apply to a single column by omitting the REPEAT (or SPAN in IE 4) attribute. By assigning an integer value to the REPEAT attribute, you direct the browser to ply the COL element's width or style settings to said number of contiguous columns. The REPEAT element is similar to the COLGROUP element's COLSPAN attribute. In concert with the COLGROUP element, the COL element allows you to create a kind of subset of related columns within a COLGROUP set.

No matter how you address the column structure of your table, the total number of columns defined in all COL and COLGROUP elements should equal the physical number of columns you intend for the table. If there should be more cells in a row than columns defined in COL and COLGROUP, the browser probably has to reflow the table and discard whatever incremental rendering it had accomplished. The following three skeletal examples specify HTML 4.0 tables with six columns:

<TABLE>
<COL REPEAT=6>
...
</TABLE>

<TABLE>
<COL>
<COL REPEAT=4>
<COL>
...
</TABLE>

<TABLE>
<COLGROUP>
<COL REPEAT=2></COLGROUP>
<COLGROUP SPAN=4>
...
</TABLE>

HTML 4.0 specifications for the COL element exceed the implementation in Internet Explorer 4 in some respects. For example, HTML 4.0 provides for alignment within a column to be around any character, such as the decimal point of a money amount. This kind of feature adds to the rationale behind the COL element. For example, you can have a table whose first three columns are formatted one way and a fourth column assigned a special style and its own alignment characteristics:

<HTML>
<HEAD>
<STYLE TYPE="text/css">
  .colHdrs {color:black}
  .normColumn {color:green}
  .priceColumn {color:red}
</STYLE>
</HEAD>
<BODY>
<TABLE>
<COLGROUP CLASS="normColumn" SPAN=3></COLGROUP>
<COL CLASS="priceColumn" ALIGN="char" CHAR=".">
<THEAD CLASS="colHdrs">
<TR><TH>Stock No.<TH>In Stock<TH>Description<TH>Price</TR>
<TBODY>
<TR><TD>8832<TD>Yes<TD>Brass Frobnitz<TD>$255.98</TR>
<TR><TD>8835<TD>No<TD>Frobnitz (black)<TD>$98</TR>
...
</TABLE>
</BODY>
</HTML>

Because attributes of the COL and COLGROUP elements apply to the entire column, in the preceding example the style sheet rule for the THEAD overrides the color settings for the two column styles for the rows enclosed by the THEAD element. The preceding example works in IE 4 for Windows, except for the alignment of the final column, which is ignored; IE 4 for the Mac assigns styles and other attributes to the wrong columns.

 
Example
<COL CLASS="dateCols" WIDTH="15" ALIGN="right">
 
Object Model Reference
IE [window.]document.all.elementID
ALIGNNN n/a   IE 3   HTML 4
ALIGN="alignConstant"Optional
 

Establishes the horizontal alignment characteristics of content within column(s) covered by the COL element. The HTML 4.0 specification defines settings for the ALIGN attribute that are not yet reflected in the CSS specification. Therefore, this ALIGN attribute is not fully deprecated. As a rule, alignment should be specified by style sheet wherever possible.

 
Example
<COL CLASS="dateCols" WIDTH="15" ALIGN="right">
 
Value
HTML 4.0 and IE 4 have two sets of attribute values:
Value IE 4 HTML 4.0
center
* *
char
- *
justify
- *
left
* *
right
* *
The values center, left, and right are self-explanatory. The value justify is intended to space content so that text is justified down both left and right edges. For the value char, the CHAR attribute must also be set to specify the character on which alignment revolves. In the HTML 4.0 specification example, content that does not contain the character appears to be right-aligned to the location of the character in other rows of the same column. It is important to bear in mind that the ALIGN attribute applies to every row of a column, including any TH element you specify for the table. If you want a different alignment for the column header, override the setting with a separate ALIGN attribute or text-align style sheet attribute for the THEAD or individual TH elements.
 
Default left
 
Object Model Reference
IE [window.]document.all.elementID.align
CHARNN n/a   IE n/a   HTML 4
CHAR="character"Optional
 

The CHAR attribute defines the text character used as an alignment point for text within a column. This attribute is of value only for the ALIGN attribute set to "char".

 
Example
<COL CLASS="priceColumn" ALIGN="char" CHAR=".">
 
Value
Any single text character.
 
Default None.
CHAROFFNN n/a   IE n/a   HTML 4
CHAROFF="length"Optional
 

The CHAROFF attribute lets you set a specific offset point at which the character specified by the CHAR attribute is to appear within a cell. This attribute is provided in case the browser default positioning does not meet with the design goals of the table.

 
Example
<COL CLASS="priceColumn" ALIGN="char" CHAR="." CHAROFF="80%">
 
Value
Any length value in pixels or percentage of cell space.
 
Default None.
REPEATNN n/a   IE n/a    HTML 4
REPEAT="columnCount"Optional
 

Defines the number of adjacent columns for which the COL element's attribute and style settings apply. If this attribute is missing, the COL element governs a single column. You can combine multiple COL elements of different REPEAT sizes as needed for your column subgrouping.

This HTML 4.0 attribute is represented in IE 4 by the SPAN attribute.

 
Example
<COL REPEAT=3>
 
Value
Integer value greater than zero.
 
Default 1
SPANNN n/a   IE 3   HTML n/a
SPAN=columnCountOptional
 

Defines the number of adjacent columns for which the COL element's attribute and style settings apply. If this attribute is missing, the COL element governs a single column. You can combine multiple COL elements of different SPAN sizes as needed for your column subgrouping.

This IE 4 attribute is represented in HTML 4.0 by the REPEAT attribute.

 
Example
<COL SPAN=3>
 
Value
Integer value greater than zero.
 
Default 1
 
Object Model Reference
IE [window.]document.all.elementID.span
VALIGNNN n/a   IE 4   HTML 4
VALIGN="alignmentConstant"Optional
 

Determines the vertical alignment of content within cells of the column(s) covered by the COL element. You can override the vertical alignment for a particular cell anywhere in the column.

 
Example
<COL VALIGN="middle">
 
Value
Four constant values are recognized by both IE 4 and HTML 4.0: top | middle | bottom | baseline. With top and bottom, the content is rendered flush (or very close to it) to the top and bottom of the table cell. Set to middle (the default), the content floats perfectly centered vertically in the cell. When one cell's contents might wrap to multiple lines at common window widths (assuming a variable table width), it is advisable to set the VALIGN attributes of all cells in the same row (or all COL elements) to baseline. This assures that the character baseline of the first (or only) line of a cell's text aligns with the other cells in the row--usually the most aesthetically pleasing arrangement.
 
Default middle
 
Object Model Reference
IE [window.]document.all.elementID.vAlign
WIDTHNN n/a   IE 4   HTML 4
WIDTH="multiLength"Optional
 

Defines the maximum width for the column(s) covered by the COL element. In practice (in IE 4 Windows, anyway), the browser won't render a column narrower than the widest contiguous stretch of characters not containing whitespace (e.g., the longest word). The precise measure of such a column width, of course, depends on the font characteristics of the content, as well. Internet Explorer 4 for the Mac mixes up column width assignments when the COL element is deployed.

 
Example
<COL WIDTH=100>
 
Value
Internet Explorer 4 accepts length values for the WIDTH in the form of pixel measures (without the "px" unit) or percentage of available horizontal space allocated to the entire table (WIDTH="25%"). The HTML 4.0 specification introduces an additional length measurement scheme to supplement the regular length measure. Called a proportional length (also MultiLength), this format features a special notation and geometry. It is best suited for situations in which a COL element is to be sized based on the available width of the table space after all fixed length and percentage lengths are calculated. Using the proportional length notation (a number followed by an asterisk), you can direct the browser to divide any remaining space according to proportion. For example, if there is enough horizontal space on the page for 100 pixels after all other column width calculations are performed, three COL elements might specify WIDTH attributes of 1*, 3*, and 1*. This adds up to a total of five proportional segments. The 100 available pixels are handed out to the proportional columns based on their proportion to the whole of the remaining space: 20, 60, and 20 pixels, respectively.
 
Default Determined by browser calculation.
Hosted by uCoz