HTML <col> Tag

The <col> element is used to provide common attributes to all cells in a column or a group of columns in a table. It is generally placed in a <colgroup> tag.

It is useful to make styles for all columns instead of repeating styles for each cell and for each row.

Syntax

The <col> element is an empty which means that it has not a closing tag in HTML.

But in XHTML the <col> tag must be properly closed with <col /> tag.

Example

<!DOCTYPE html>
<html>
 <head>
   <style>
     table, th, td {
       border-collapse: collapse;
       border: 1px solid;
     }
     th, td {
       padding: 10px;
     }
   </style>
 </head>
 <body>
   <table style="margin:30px;">
     <colgroup>
       <col span="2" style="background-color:#e1e1e1; width:160px;">
       <col style="background-color:#1c87c9; width:80px;">
     </colgroup>
     <tr>
       <th>Name</th>
       <th>Gender</th>
       <th>Age</th>
     </tr>
     <tr>
       <td>Ruby Sparks</td>
       <td>Female</td>
       <td style="text-align:center;">19</td>
     </tr>
     <tr>
       <td>John Smith</td>
       <td>Male</td>
       <td style="text-align:center;">23</td>
     </tr>
   </table>
 </body>
</html>

Attributes:

Most of attributes which were used in HTML4.01 are not supported by HTML5 at the moment.

Attributes Value Description
align left
right
center
justify
char
Defines the alignment of the content which is related to the <col> element.
This attribute is not supported by HTML5.
char character Defines the alignment of the content which is related to the <col> element's character.
This attribute is not supported by HTML5.
charoff number Defines characters' numbers which the content will be aligned from the character. It is defined by char attribute.
This attribute is not supported by HTML5.
span number Defines the number of columns which a <col> element should span.
valign top
bottom
middle
baseline
Defines vertical alignment of the content which is related to the <col> element.
This attribute is not supported by HTML5.
width %
pixels
relative_length
Defines the width of the <col> element.
This attribute is not supported by HTML5.

The <col> tag also uses the Global Attributes.