The <colgroup>
tag in HTML is used to group together a set of columns in a table and apply common properties to them. This tag is typically used in conjunction with the <table>
tag to define the layout and appearance of a table.
The <colgroup>
tag is placed directly after the opening <table>
tag and before the <thead>
, <tbody>
, or <tfoot>
tags. Within the <colgroup>
tag, you can define one or more <col>
tags, each of which represents a single column in the table. The <col>
tag has various attributes that can be used to specify properties such as the width, background color, and text alignment of the column.
Here is an example of how the <colgroup>
tag might be used in HTML:
<table>
<colgroup>
<col style=”background-color: #ccc;”>
<col style=”text-align: center;”>
<col>
</colgroup>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
<td>Row 1, Column 3</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
<td>Row 2, Column 3</td>
</tr>
</tbody>
</table>
In this example, the <colgroup>
tag is used to group together three columns in the table. The first column has a gray background color, the second column is centered, and the third column has no specific styling. The <thead>
and <tbody>
tags are used to define the header and body sections of the table, respectively, and the individual cells are defined using the <th>
and <td>
tags.
[…] <colgroup> […]