HTML Table Colgroup
HTML Table Colgroup
The <colgroup> and the <col> elements
are used to style specific columns of a table.
| MON | TUE | WED | THU | FRI | SAT | SUN |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
The <colgroup> element should be used as a container for the column
specifications.
Each group is specified with a <col> element.
The span attribute specifies how many columns get the style.
The style attribute specifies the style to give the columns.
Example
<table>
<colgroup>
<col span="2"
style="background-color: #D6EEEE">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
...
Try it Yourself »
Note: The <colgroup> tag must be a
child of a <table> element and should be placed
before any other table elements, like <thead>,
<tr>, <td>
etc., but after the <caption> element, if
present.
Legal CSS Properties in <col>
Here are the CSS properties that can be used in the <col>
tag:
Other CSS properties will have no effect.
Style Multiple Columns
To style multiple columns with different styles, use more than one <col> element inside the
<colgroup>:
| MON | TUE | WED | THU | FRI | SAT | SUN |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Example
<table>
<colgroup>
<col span="5"
style="background-color: #D6EEEE">
<col span="2"
style="background-color: pink">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
...
Try it Yourself »
Style Last Columns
To style for example the last two columns, insert an "empty"
<col> element (with no styles) for the columns before:
| MON | TUE | WED | THU | FRI | SAT | SUN |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Example
<table>
<colgroup>
<col span="5">
<col
span="2"
style="background-color: pink">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
...
Try it Yourself »
Hide Columns
You can hide columns with the visibility: collapse property:
Example
<table>
<colgroup>
<col span="5">
<col span="2"
style="visibility: collapse">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
...
Try it Yourself »