<col> Tag in HTML

The <col> tag is used to define column properties in an HTML table. It is a self-closing tag that provides styling information for columns in a <table> element. The <col> tag is useful when you want to apply styles to individual columns of a table.

Key Points on <col> Tag:

Syntax of <col> Tag:

Syntax Example

<col> or <col style="property:value">

Example of <col> Tag in HTML:

This example demonstrates how to use the <col> tag to apply styling to table columns.

Code Example


        <table>
          <colgroup>
            <col style="background-color: blue;">
            <col style="background-color: green;">
            <col style="background-color: yellow;">
          </colgroup>
          <tr>
            <td>Row 1, Column 1</td>
            <td>Row 1, Column 2</td>
            <td>Row 1, Column 3</td>
          </tr>
          <tr>
            <td>Row 2, Column 1</td>
            <td>Row 2, Column 2</td>
            <td>Row 2, Column 3</td>
          </tr>
        </table>
                

Output

Row 1, Column 1 Row 1, Column 2 Row 1, Column 3
Row 2, Column 1 Row 2, Column 2 Row 2, Column 3

Attributes of <col> Tag:

The <col> tag is an effective way to apply styles such as background color, width, or other CSS properties to entire columns in a table. It's commonly used when working with large tables and when you need consistent styling across multiple rows in the same column.