HTML col Tag defines the specific properties of a particular column of a table element.
Table of Contents
Syntax of HTML col Tag
The Syntax of HTML col Tag is shown below. It is self closing tag.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<colgroup>
<col span="2" style="background-color:red">
<col span="2" style="background-color:blue">
</colgroup>
</body>
</html>
Usage of HTML col Tag
HTML col Tag is used inside the colgroup tag to define the properties of a specific column. Col tag is useful to apply same style to whole column instead of applying css to every cell, individually within the column.
The span attribute defines the span of a column inside the colgroup element.
Example of HTML col Tag
Simple example of HTML col Tag is shown below.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<colgroup>
<col span="1" style="background-color:red">
<col span="1" style="background-color:yellow">
</colgroup>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>Jade</td>
<td>93</td>
</tr>
</table>
</body>
</html>
Output
The output of code above is shown below.
Name | Marks |
---|---|
Jade | 93 |
Browser Support for HTML col Tag
HTML col Tag is supported by all major browsers.
Global Attributes Support in HTML col Tag
The HTML col Tag supports all Global Attributes.
Event Attributes Support in HTML col Tag
The HTML col Tag supports all Event Attributes.
HTML col Tag Video
Watch our video on HTML col Tag and subscribe our Youtube Channel.