HTML <colgroup> Tag

Description

The <colgroup> HTML element is intended to specify the width and style of one or more columns of the table. This element allows you to reduce the code of the table by reducing duplicate attributes, and if it is available, the browser starts showing the contents of the table, without waiting for it to fully load. The <colgroup> element can be used in combination with <col> , which defines the characteristics of one or more columns.
Usually, a closing tag is not required, but if the <colgroup> acts as a container for the <col> elements, then the </colgroup> tag should be added at the end of the group.

Properties

Permitted Parents
A <table> element. The <colgroup> must appear after any optional <caption> element but before any <thead>, <th>, <tbody>, <tfoot> and <tr> element.
Content
0 or more <col> elements
Start/End Tags
Start tag: required, End tag: required

Example

<table width="100%" border="1">
<colgroup span="2" align="left"></colgroup>
<colgroup align="right" style="color:red;"></colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
</table>

Attributes

Attribute Definition
span Specifies how many columns to span.
width Width of the column.
align Specifies the alignment of the content related to a col element.
valign Specifies the vertical alignment of the content related to a col element.
char Specifies the alignment of the content related to a col element to a character.
charoff Specifies the number of characters the content will be aligned from the character specified by the char attribute.

Global Attributes

The <colgroup> tag also supports the Global Attributes in HTML5

Event Attributes

The <colgroup> tag also supports the Event Attributes in HTML5

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
YesYes11YesYes
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYes4YesYesYes