<COLGROUP>NN 6 IE 3 HTML 4  

<COLGROUP>...</COLGROUP>

HTML End Tag: Optional  

The colgroup element provides shortcuts to assigning widths and other characteristics (styles) to one or more subsets of columns within a table. With this information appearing early in the table element source code, 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 colgroup element in combination with the col element or by itself. You may also define a colgroup that has col elements nested within to assist in defining subsets of columns that share some attribute or style settings. The need for the element's end tag is determined by the presence of standalone col elements following the colgroup element. For example, if you specify column groupings entirely with colgroup elements, end tags are not necessary:

If you have a freestanding col element following the colgroup element, you must clearly end the colgroup element before the standalone col element:

The structure depends on how you need to assign widths and styles to individual columns or contiguous columns. To create a column grouping that consists of multiple adjacent columns, use the span attribute. This is entirely different from the colspan attribute of a td element, which has the visual impact of joining adjacent cells together as one. The span attribute helps define the number of columns to be treated structurally as a group (for assigning attribute and style sheet settings across multiple columns, regardless of the column content).

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. The following three skeletal examples specify HTML 4 tables with six columns:

HTML 4 specifications for the colgroup element exceed the implementation in IE for Windows and Navigator through Version 6. For example, HTML 4 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 (see the col element for an example).

Syntactically, there is little difference between a colgroup and col element. A colgroup element, however, lends a structural integrity to a group of columns that is rendered differently when the containing table element specifies rules="groups"; the browser draws rule lines (standard table borders in IE) only between colgroup elements, and not col elements.

Support indicated here for Netscape 6 is based on the browser's DOM implementation. The DOM reports to scripts that the colgroup element and its attributes exist (reflected as properties). But as of Netscape 7, the element does not perform its intended tasks. A later version will likely connect the element's internal wiring.

 
Example
 
<COLGROUP class="dateCols" width="15" align="right">
 
Object Model Reference
 
[window.]document.getElementById(elementID)
 
Element-Specific Attributes
 
aligncharcharoffspanvalign
width
 
Element-Specific Event Handler Attributes

None.

alignNN n/a IE 3 HTML 4  

align="alignConstant"

Optional  

Establishes the horizontal alignment characteristics of content within column(s) covered by the colgroup element. The HTML 4 specification defines settings for the align attribute that are not yet reflected in the CSS specification. For example, there is no CSS equivalent for the alignment by character. See the colgroup element description about Netscape 6 compatibility.

 
Example
 
<COLGROUP class="dateCols" width="15" align="right" span="3">
 
Value

HTML 4 and IE have two sets of attribute values.

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 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
 
[window.]document.getElementById(elementID).align
charNN 6 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". Microsoft documents a ch attribute, which corresponds to the standards-based char attribute. In any case, the browser does not respond to either attribute. Netscape 7 has not yet connected support for the char attribute.

 
Example
 
<COLGROUP class="priceCols" align="char" char="." span="2">
 
Value

Any single text character.

 
Default

None.

charoffNN 6 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. Microsoft documents a choff attribute, which corresponds to the standards-based charoff attribute. In any case, the browser does not respond to either attribute. Netscape 7 has not yet connected support for the charoff attribute.

 
Example
 
<COLGROUP class="priceColumn" align="char" char="." charoff="80%" span="2">
 
Value

Any length value in pixels or percentage of cell space.

 
Default

None.

langNN 3 IE 4 HTML 4  

lang="languageCode"

Optional  

The language being used for the element's attribute values and content. A browser can use this information to assist in proper rendering of content with respect to details such as treatment of ligatures (when supported by a particular font or required by a written language), quotation marks, and hyphenation. Other applications and search engines might use this information to aid the selection of spell-checking dictionaries and the creation of indices.

 
Example
 
<SPAN lang="de">Deutsche Bundesbahn</SPAN>
 
Value

Case-insensitive language code.

 
Default

Browser default.

 
Object Model Reference
 
[window.]document.getElementById(elementID).lang
spanNN n/a IE 3 HTML 4  

span="columnCount"

Optional  

Defines the number of adjacent columns for which the colgroup element's attribute and style settings apply. If this attribute is missing, the colgroup element governs a single column. You can combine multiple colgroup elements of different span sizes as needed for your column subgrouping. See the colgroup element description about Netscape 6 compatibility.

 
Example
 
<COLGROUP span="3">
 
Value

Integer value greater than zero.

 
Default

1

 
Object Model Reference
 
[window.]document.getElementById(elementID).span
valignNN 6 IE 3 HTML 4  

valign="alignmentConstant"

Optional  

Determines the vertical alignment of content within cells of the column(s) covered by the colgroup element. You can override the vertical alignment for a particular cell anywhere in the column. See the colgroup element description about Netscape 6 compatibility.

 
Example
 
<COLGROUP valign="middle">
 
Value

Four constant values are recognized by both IE 4 and HTML 4: 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 colgroup 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 rowusually the most aesthetically pleasing arrangement.

 
Default

middle

 
Object Model Reference
 
[window.]document.getElementById(elementID).vAlign
widthNN 6 IE 3 HTML 4  

width="multiLength"

Optional  

Defines the maximum width for the column(s) covered by the colgroup element. In practice (in IE 4 and later for 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. See the colgroup element description about Netscape 6 compatibility.

 
Example
 
<COLGROUP width="100">
 
Value

Internet Explorer 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%").

An alternate variation of the proportional length value is described in the HTML 4.0 specification. For a colgroup element, you can specify width="0*" to instruct the browser to render all columns according to the minimum width necessary to display the content of the cells in the column. For a browser to make this calculation, it must load all table contents, thus eliminating the possibility of incremental rendering of a long table. For more information about proportional lengths, see the width attribute of the col element.

 
Default

Determined by browser calculation.