colgroup for column grouping

The colgroup element represents a set of columns. The span attribute specifies how many columns the colgroup element applies to. The irregular cells are counted as part of the column they start in.

The colgroup element includes all of the cells in a column including thead and tfoot, and it matches both th and td elements. The colgroup element relates to elements that are not contained within the element. A selector such as #colgroup1 > td doesn't match any elements.

In the following example, the first colgroup in the listing applies to the first three columns in the table, and the other element applies to the next two columns.

#colgroup1 {background-color: red} 
#colgroup2 {background-color: green; font-size:small} 
        <colgroup id="colgroup1" span="3"/> 
        <colgroup id="colgroup2" span="2"/> 
                <th>Header 1</th><th>Header 2</th><th>Header 3</th><th colspan="2">Header 4</th> 
               <th>X</th><td>Y</td><td colspan="2" rowspan="2">Z</td><td>Q</td> 
               <th rowspan="2">1</th><td>2</td><td rowspan="2">3</td> 
                <th colspan="5">Line</th> 
Click to view this demo.
  HTML CSS Book