Example of HTML colgroup Tag

Example: In this example, we will see the implementation of HTML colgroup tag.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <title>HTML5 colgroup Tag</title>
</head>

<body>
    <h1>w3wiki</h1>
    <h2>HTML colgroup tag</h2>
    <table>
        <!-- colgroup tag starts here-->

        <colgroup>
            <col span="2" 
                 style="background-color: green; color: white" />
            <col style="background-color: tomato" />

            <!-- colgroup tag ends here-->
        </colgroup>
        <tr>
            <th>STUDENT</th>
            <th>COURSE</th>
            <th>AGE</th>
        </tr>
        <tr>
            <td>Manas Chhabra</td>
            <td>BCA</td>
            <td>19</td>
        </tr>
        <tr>
            <td>Anurag Gupta</td>
            <td>B.TECH</td>
            <td>23</td>
        </tr>
    </table>
</body>

</html>

Output: 

Supported Browsers: 

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 15
  • Safari 4

HTML Tag

HTML is a versatile language, and one of its most useful elements is the <colgroup> tag. This tag is used to group one or more columns in a table for formatting purposes. It’s a handy tool for applying styles to entire columns, saving you the trouble of repeating styles for each cell.

Similar Reads

Understanding the  Tag

The  tag is used in conjunction with the  tag. The  tag is nested within the  tag and is used to define properties for columns....

Example of HTML colgroup Tag

Example: In this example, we will see the implementation of HTML colgroup tag....

Contact Us