colgroup element | colGroup object
[This documentation is preliminary and is subject to change.]
Specifies property defaults for a column or group of columns in a table.
![]() |
Standards information
- HTML 4.01 Specification, Section 11.2.4
HTML information
| Closing Tag | required |
|---|---|
| CSS Display | block |
DOM Information
Inheritance Hierarchy
Remarks
Nested COL elements override COLGROUP elements.
Use the SPAN attribute to specify the number of table columns that the COLGROUP defines. This attribute has a default value equal to one.
COL elements can occur outside of a COLGROUP element, and these two elements can be used for similar purposes. However, you must use the COLGROUP element to determine where table internal dividing lines (rules) should go. This is illustrated in the first example .
You should avoid using the SPAN attribute inside the COLGROUP element if there are COL elements nested within it. This is because the SPAN attribute that belongs to the nested COL elements will override the attribute that belongs to the COLGROUP element. This can cause confusing code and possibly unintended results. This behavior is illustrated in the second example.
The table object and its associated elements have a separate table object model, which uses different methods than the general object model. For more information on the table object model, see Building Tables Dynamically.
Windows Internet Explorer 8 will only render tables up to 1000 columns. To force Windows Internet Explorer 7 rendering mode, see How Do I Take Advantage of the New Features in Internet Explorer 8.
Examples
This example uses the COLGROUP element to assign specific characteristics to two groups of columns in a table.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/colgroupEX1.htm
<html>
<body>
<table border="2" rules="groups">
<!-- RULES is set to "groups", which places internal dividing lines around
table columns defined by COLGROUP. -->
<colgroup span="2" style="color: red">
</colgroup>
<colgroup style="color: blue">
</colgroup>
<tr>
<td>This column is in the first group.</td>
<td>This column is in the first group.</td>
<td>This column is in the second group.</td>
</tr>
<tr>
<td>This column is in the first group.</td>
<td>This column is in the first group.</td>
<td>This column is in the second group.</td>
</tr>
</table>
</body>
</html>
When COL elements are nested inside a COLGROUP element, the attributes of the COL elements override the attributes of the COLGROUP element. In this example, the last column has no formatting even though COLGROUP spans over all three columns. This happens because the SPAN attribute of the nested COL element overrides the SPAN attribute of the COLGROUP.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/colgroupEX2.htm
<html>
<body>
<table border="2">
<colgroup span="3" style="color: green; background: black">
<!-- Styling is applied to only the first two columns, instead of all
three, and the font color is red instead of green. This is consistent
with the attributes of the COL element. -->
<col span="2" style="color: red">
</colgroup>
<tr>
<td>This column is in the first group.</td>
<td>This column is in the first group.</td>
<td>This column is in the second group.</td>
</tr>
<tr>
<td>This column is in the first group.</td>
<td>This column is in the first group.</td>
<td>This column is in the second group.</td>
</tr>
</table>
</body>
</html>
See also
Build date: 3/8/2012
so I tested it on other browsers
Separating line is available when I open demo page of firs example with firefox and safari, and Opera shows something like separing line, but only IE shows colors.
In this situation this element/object is useless
- 3/15/2010
- Ventsislav Alexandriyski
- 6/25/2010
- Thomas Lee
