asp.net.ph

Skip Navigation Links

COLGROUP Element | COLGROUP Object

Language References


Specifies a group of columns. HTML 4, 4.01, 5

HTML Syntax

Remarks

The COLGROUP element creates an explicit column group. The number of columns in the column group may be specified in two ways:

  • The element’s span attribute ( default value 1 ) specifies the number of columns in the group.
  • Each COL element in the COLGROUP represents one or more columns in the group.

The advantage of using the span attribute is that authors may group together information about column widths. Thus, if a table contains ten columns, all of which have a width of 20 pixels, it is easier to write:

<colgroup span="10" width="20"></colgroup>

than:

<colgroup>
   <col width="20">
   <col width="20">
   ... a total of ten COL elements ...
</colgroup>

When it is necessary to single out a column ( e.g., for style information, to specify width information, etc. ) within a group, authors must identify that column with a COL element. Thus, to apply special style information to the last column of the previous table, we single it out as follows:

<colgroup width="20">
   <col span="9">
   <col id="diffCol">
</colgroup>

The width attribute of the COLGROUP element is inherited by all 10 columns. The first COL element refers to the first 9 columns ( doing nothing special to them ) and the second one assigns an id value to the tenth column so that style sheets may refer to it.

THE COLGROUP element greatly simplifies the application of various column group attributes. In previous HTML versions, if authors wanted to apply an attribute to an entire column, such as width, span, alignment or style, the attribute had to be coded for each and every cell in the column.

This was not only inefficient as it was cumbersome, but takes longer for browsers to parse cell rendering instructions, and adds to file size as well, especially with larger tables, hence decreasing overall download speed.

Members

COLGROUP Members

Example

<table>
<colgroup align="right">
<colgroup span=2 align="left">
<tbody>
<tr>
   <td>This column is in the first group and is right-aligned.</td>
   <td>This column is in the second group and is left-aligned.</td>
   <td>This column is in the second group and is left-aligned.</td>
</tr>
</table>
This column is in the first group and is right-aligned. This column is in the second group and is left-aligned. This column is in the second group and is left-aligned.

See Also

COL



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note