HTML <colgroup> widthAttribute

HTML colgroup 标签参考手册HTML <colgroup> Tag

Examples

A <colgroup> element that specifies a predefined width of 200 pixels for the first column:

<table border="1">
  <colgroup width="200">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the width attribute. However, no browser supportsrelative_lengthvalue.


Definition and Usage

In HTML5, the <colgroup> width attribute is not supported.

The width attribute specifies the width of a column group.

Usually, the space occupied by a column group is the space needed to display its content. The width attribute is used to set a predefined width for the column group.

Note:This attribute is overridden by any width setting in a <col> element.


Syntax

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

Attribute Values

Value Description
pixels Sets the width value in pixels (example: width="50").
% Sets the width value as a percentage of the enclosing element (example: width="50%").
relative_length Distributes available pixels among the parts. Part one is set to "1*", part two is set to "2*". (For example, if the table width is 100px, the first column group is 20px, the second column group is 50%, then the remaining available pixels are 30px.)

Example: If the available pixels are 30px, you can set part one to "1*" and part two to "2*", which will be interpreted as 10 and 20 pixels ("1*" for part one, "2*" for part two).



HTML colgroup 标签参考手册HTML <colgroup> Tag Other Extensions