<colgroup>...</colgroup>

HTML4 HTML5

The <colgroup> tag defines a group of table columns for formatting.

Opening tag is required, closing tag is optional. Placed inside <table> after <caption> and before <thead>, <tbody>, <tfoot>, and <tr>.

Attributes:

span="..." - Number of columns in the group.

align="..." - (left, right, center, justify, char) Text alignment. Not in HTML5.

char="..." - Alignment character. Not in HTML5.

charoff="..." - Alignment character offset. Not in HTML5.

valign="..." - (top, middle, bottom, baseline) Vertical alignment. Not in HTML5.

width="..." - Column group width. Not in HTML5.

Example

Code:

<table>
  <caption>Car fuel consumption</caption>
  <colgroup>
    <col span="2" style="background-color:green">
    <col style="background-color:yellow">
  <colgroup>
  <tr>
    <th>Fueled [l]</th>
    <th>Price [PLN/l]
    <th>Driven [km]</th>
  </tr>
  <tr>
    <td>42.4</td>
    <td>5.06</td>
    <td>815</td>
  </tr>
  <tr>
    <td>40.7</td>
    <td>5.21</td>
    <td>786</td>
  </tr>
</table>

The browser will interpret this code as follows:

Car fuel consumption
Fueled [l]Price [PLN/l]Driven [km]
42.4 5.06 815
40.7 5.21 786