Open In App

HTML <colgroup> width Attribute

Last Updated : 20 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML <colgroup> width Attribute is used to specify the width of the colgroup element. The <colgroup> attribute sets a predefined width of the column group.

Syntax

<colgroup width="pixels|%|relative_lngth">

Attribute Values

Value

Description

pixels

It specify the width of the colgroup in terms of pixels.

%

It specify the width of the colgroup element in percent. For ex-width=”50%”

relative_length

It divides the length of the table in terms of pixels.

Note: The width attribute is not supported by HTML 5.

Example: In this example, we will set the width of the colgroup element.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML colgroup width Attribute
    </title>

    <style>
        h2 {
            text-align: center;
        }
        
        #myColGroup {
            background: green;
        }

        table {
            border: 2px solid #000;
            color: white;
            background: #fff;
            margin: auto;
        }

        td {
            padding: 10px;
        }
    </style>
</head>

<body>
    <h2>HTML colgroup width Attribute</h2>

    <table>
        <colgroup id="myColGroup" span="3" 
            align="left" width="150">
        </colgroup>
        
        <tr>
            <th>S.No</th>
            <th>Title</th>
            <th>Geek_id</th>
        </tr>
        <tr>
            <td>1</td>
            <td>GeekforGeeks</td>
            <td>Geek_id_1</td>
        </tr>
        <tr>
            <td>2</td>
            <td>GFG</td>
            <td>Geek_id_2</td>
        </tr>
    </table>
</body>

</html>

Output

HTML-Colgroup-Width-Attribute

Supported Browsers

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


Next Article

Similar Reads