HTML colgroup tag

HTML <colgroup> tag groups all the columns. It contains one or more columns. colgroup is the child of table element.

<table class="demoBox">
 <colgroup>
  <col style="background-color:lightgreen;">
  <col style="background-color:lightblue;">
  <col style="background-color:lightyellow;">
 </colgroup>
 <tr>
  <th>Countries</th>
  <th>Population</th>
  <th>Area</th>
 </tr>
 
 <tr>
  <td>China</td>
  <td>7,432,663,275</td>
  <td>9,572,900</td>
 </tr>
 
 <tr>
  <td>India</td>
  <td>1,382,323,332</td>
  <td>3,287,263</td>
 </tr>
 
 <tr>
  <td>Unitd States</td>
  <td>324,118,787</td>
  <td>9,525,067</td>
 </tr>

</table>

</>
Countries Population Area
China 7,432,663,275 9,572,900
India 1,382,323,332 3,287,263
Unitd States 324,118,787 9,525,067

Tag Uses

Specific uses of <colgroup> tag

HTML colgroup element contains one or more columns. It can style more than one columns rather than individually.

Tag omission

The closing tag (</colgroup>) of colgroup may be omitted.

Global Attributes

All global attributes are applicable on colgroup element.

Tag Attributes

Attributes that are applicable to <colgroup> tag
span

If colgroup does't contain any column then this attribute should be use.

<colgroup span="2"> <col></col> </colgroup>


Was this article helpful?