Description
HTML element <col>
is used to define column properties for each column within the <colgroup>
element.
It is commonly used to apply styles to entire columns, instead of applying them individually to each row and cell.
The below table summarizes its usage.
Usage Details | |
Placement | It is a child element of <colgroup> element, which is part of <table> element. |
Contents | It is an empty element, which doesn't contain any content. |
Tags | Only an opening tag is required. |
Versions | HTML 4, 4.01, and 5 |
Syntax
Here is the basic syntax of the <col>
element.
- The attribute span is optional, which can be used to column-span with a number to represent the number of columns it span.
<col span="num">
Examples
In the below example, the <col>
element is used to refer to a movie and a painting.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h1>HTML Element - col</h1>
<table>
<colgroup>
<col style="background-color: gray;">
<col span="2" style="background-color: blue;">
</colgroup>
<tr>
<th>Product</th>
<th>Sales</th>
<th>Stock</th>
</tr>
<tr>
<th>Bread</th>
<th>10000</th>
<th>20000</th>
</tr>
<tr>
<th>Butter</th>
<th>3000</th>
<th>8000</th>
</tr>
</table>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <col>
tag.
Attribute Type | Details |
Element-Specific Attributes | The tag <col> has some element-specific attributes listed in the below table |
Global Attributes | Like all other HTML tags, the tag <col> supports the HTML Global Attributes. |
Event Attributes | The tag <col> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <col>
element.
Attribute | Value | Description |
span | length | Specifies the number of consecutive columns the <col> element spans, with default value as 1 .A negative value is not allowed. |
Browser Compatibility
The tag <col>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 4+
- Firefox 1+
- Apple Safari 1+
- Opera 7+