The HTML <col> tag allows authors to group together attribute specifications for table columns. The does not group columns together structurally -- that is the role of the element.
The elements are empty and serve only as a support for attributes.
<!DOCTYPE html>
<html>
<head>
<title>HTML col Tag</title>
</head>
<body>
<p>This example shows a colgroup that has three columns of different widths:</p>
<table border="1">
<colgroup span="3">
<col width="50"></col>
<col width="100"></col>
<col width="150"></col>
<col width="50"></col>
</colgroup>
<tr>
<td>col 1</td>
<td>col 2</td>
<td>col 3</td>
<td>col 4</td>
</tr>
</table>
</body>
</html>
This will produce following result:
This example shows a colgroup that has three columns of different widths:
col 1 | col 2 | col 3 |
col 4 |
The HTML <col> tag also supports following additional attributes:
Attribute | Value | Description |
---|---|---|
align | right left center justify char |
Defines horizontal alignment, not supported in Html5. |
char | character | Defines a character to use to align text on (use with align="char"), not supported in Html5. |
charoff | pixel | Specifies an alignment offset (either in pixels or percentage value) against the first character as specified with the char attribute, not supported in Html5. |
span | number | Defines the number of columns the <col> should span, not supported in Html5. |
valign | bottom middle top baseline |
Defines vertical alignment, not supported in Html5. |
width | pixels or % | Specifies a default width for each column spanned by the current col element, not supported in Html5 . |