colgroup
Definition and Usage
The <colgroup> tag specifies a group of one or more columns in a table for formatting within a table. Or in other words , Thecolgroup
is a container for a number of col
elements, and allows you to set attributes that you might otherwise set at col
level on a number of col
elements simultaneously—the attributes defined at this higher level apply to all of the child columns. It is important to note that if you use one or more colgroup
then all col
s must be enclosed in one or more colgroup
s .The <colgroup> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row. The HTML <colgroup>
tag is used for specifying properties for a group of columns within a table.Must be used as a child of a <table> element, after any <caption> elements and before any <thead>, <tbody>, <tfoot>, and <tr> elements.If you need to apply different properties to a column within a colgroup, you can use the HTML <col> tag within the colgroup tag.
Syntax
<table>
<colgroup>
<col class="col-1">
<col span="2" class="normal">
</colgroup>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
</table>