Kanbritech Learn logo
HTML HTML Tutorial 45h track

Table Colgroup

Group the first two columns of a three-column table.

Understand the topic

colgroup and col describe groups of table columns. They appear after any caption and before the row groups. A col span can represent several adjacent columns. Only certain CSS effects, including column backgrounds and widths, apply as expected to columns; properties such as text alignment usually need to be applied to cells themselves.

Worked example

<table><caption>Workshop places</caption><colgroup><col style="background: #dcfce7;"><col></colgroup><tr><th scope="col">Class</th><th scope="col">Places</th></tr><tr><td>HTML</td><td>12</td></tr></table>

The first col gives the first column a pale background. A cell background can paint over a column background.

Practice

Group the first two columns of a three-column table.

Show a suggested answer
<colgroup><col span="2" style="background: #e0f2fe;"><col></colgroup>

Common mistake

Do not put cells inside colgroup. It describes columns but does not contain row data.

HTML documentation

Live Example

Try Coding

Result