HTML col Tag

HTML <col> Tag: The HTML<col> tag describes the column properties for each column. And this HTML col tag can be used for applying styles to the entire column instead of repeating styles for each cell and each row. This tag is used to set the style property to each column. This tag does not contain closing tags.

HTML <col> Tag

This  HTML col tag supports both the global and the event attributes.

Syntax: <colgroup> <col span=” ” style=” “></colgroup>

Attributes

span: It is used to define the number of columns on which property will be applied.
style: This attribute is used to define the CSS to change the properties of the column.
align: This attribute is used to set the alignment of the content of the <col> element.
width: It is used to specify the width of a <col> element.
charoff: It is used to specify the number of characters the content will be aligned from the character specified by the char attribute.

Browser compatibility

The HTML<col> tag is supported by chrome, firefox, opera, safari and internet explorer.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<table>
  <colgroup>
    <col span="1" style="background-color:orange">
    <col style="background-color:white">
    <col style="background-color:green">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>2178965</td>
    <td>JAVA</td>
    <td>Rs.650</td>
  </tr>
  <tr>
    <td>5869651</td>
    <td>R programming</td>
    <td>Rs.490</td>
  </tr>
</table>

</body>
</html>

Output:

HTML col tag

 

 

 

Attributes that are supported by the <col> tag

Attribute Value Description
align left
right
center
justify
char
Describes the alignment of the content related to a

element

char Character Describes the alignment of the content related to a

element to a character

charoff number Defines the number of characters the content will be aligned from the character specified by the char attribute
span number Specifies the number of columns a

element should span

valign top
middle
bottom
baseline
Specifies the vertical alignment of the content related to a

element

width %
pixels
relative_length
Specifies the width of a

element