| Depr. | Empty | Version |
|---|---|---|
| No | No | HTML 4 |
| IE5.5+ | FF1+ | SA1.3+ | OP9.2+ | CH2+ |
|---|---|---|---|---|
| Full | Full | Full | Full | Full |
Syntax
Description
The
colgroup is a container for a number of
col elements, and allows you to set attributes that you
might otherwise set at col level on a number of
col elements simultaneously—the attributes defined at
this higher level apply to all of the child columns. It is important to
note that if you use one or more colgroup then all
cols must be enclosed in one or more
colgroups
Example
This
colgroup element is used to set a
class for first three columns (which can then be
styled with CSS):
<table border="1">
<colgroup class="vivid">
<col/>
<col/>
<col/>
</colgroup>
<colgroup>
<col/>
</colgroup>
<tr>
<th colspan="4">Work Contact Points</th>
</tr>
⋮
</table>
Use This For …
This element is used to apply styles (either using HTML attributes or via CSS) to a number of columns simultaneously.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
This element has reasonable support, though the breadth of support depends heavily on which attributes are applied. Attribute support varies between browsers (it would be so much easier if all browsers tested, supported, and ignored the same set of attributes, but unfortunately, this is not the case).
A
better approach is to apply class names to the
respective colgroup elements, then let CSS styling take
care of alignment, colors, widths, and so on.
While the chart shows support as “full”, this is on the understanding that you haven’t yet applied one of the many troublesome or ignored attributes that are listed below (these individual attributes paint a very different picture on browser support!).
In this Section
- align
aligns text in cells that are related to the colgroup element - char
sets the character to which cell contents should align - charoff
defines the number of characters by which cell contents will be offset from the char - span
sets the number of col elements to which the span applies - valign
sets the vertical alignment of text in table cells - width
sets the width of the entire column group