HTML <colgroup> tag specifies group of column within an HTML table. It is used a parent container of one or more <col> elements to apply different properties in an HTML table.

NOTE: The <colgroup> tag must be used with <table> element after the <caption> and before <thead> or <tbody> elements.

Syntax

<colgroup>......</colgroup>  

Following are some specifications about the HTML <colgroup> tag

DisplayNone
Start tag/End tagStart tag and End Tag
UsageHTML tables

Example

<!DOCTYPE html>  

<html>  

<head>  

    <title>Colgroup tag</title>  

</head>  

<body>  

<h2>Example of Colgroup Tag</h2>  

<table border="1">  

    <colgroup>  

        <col  style="background-color: green" width="40">  

        <col span="2" style="background-color:   #ff7256" width="80">  

    </colgroup>  

    <tr>  

        <th>Sr.No</th>  

        <th>Product</th>  

        <th>Price</th>  

    </tr>  

    <tr>  

        <td>1</td>  

        <td>Rice</td>  

         <td>85</td>  

    </tr>  

    <tr>  

        <td>2</td>  

        <td>Butter</td>  

         <td>260</td>     

       </tr>  

    <tr>  

        <td>3</td>  

        <td>Mango</td>  

         <td>125</td>  

    </tr>  

</table>  

</body>  

</html>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *