HTML <colgroup> tag

Updated: 09/12/2023 by Computer Hope
HTML colgroup tag

When writing in HTML (hypertext markup language), the <colgroup> tag is used to denote a group of columns within a table. It is useful when you want to format many columns at the same time. The following sections contain information about this tag, including an example of it in use, and related attributes and browser compatibility.

Example of <colgroup> code

<table class="mtable2 tab">
<colgroup>
<col span="1" style="background-color:#c1c1c3">
<col style="background-color:white">
</colgroup>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>March</td>
<td>$200</td>
</tr>
<tr>
<td>April</td>
<td>$300</td>
</tr>
<tr>
<td>May</td>
<td>$250</td>
</tr>
</table>

Example result

Month Savings
March $200
April $300
May $250

As the HTML code indicates, the entire table has a background color of white and the first column is "painted" grey. The table itself has one of our CSS (cascading style sheets) classes applied to it to improve its appearance.

Deprecated attributes

All HTML tags support standard attributes that define the settings of an HTML element. In addition to the standard settings, the <colgroup> tag had the following unique attributes that are now deprecated.

Attribute Description
align Designates the alignment of content inside an attribute.
char Designates the character within a column group to align with the rest of the content.
charoff Designates the number of characters to offset the column group's content by relative to the char attribute.
span Designates the number of columns the <colgroup> element should cover.
valign Designates the vertical alignment of content with the <colgroup> element.
width Designates how wide the <colgroup> element should be.

Compatibility

Edge Internet Explorer Firefox Safari Opera Chrome
All versions All versions All versions All version All versions All versions

Browser, Class, <col>, Compatibility, Container tag, Format, Table, Web design terms