<col> : Table Column element

Introduction

The ‘<col>‘ HTML element defines a column within a table and is used for defining common semantics on all common cells. It is generally found within a ‘<colgroup>‘ element.

<col>‘ allows styling columns using CSS, but only a few properties will have an effect on the column.

Here is an example :

Output :

Uses of <col> tag :

Here are some uses of <col> tag :

1. Applying Styles to Columns : You can use the ‘<col>‘ element to apply specific styles, such as background colors, borders, or text alignment, to individual columns or groups of columns.

2. Setting Column Widths : You can use the width attribute to specify the width of a column. This is useful when you want to control the width of specific columns in the table.

3. Spanning Columns : The ‘<col>‘ element can also be used to define columns that span multiple columns. This is done using the span attribute.

4. Defining Column Attributes: You can use the ‘<col>‘ element to define various attributes for columns, such as class or id, making it easier to select and style specific columns with CSS or JavaScript.

By using the ‘<col>‘ element along with the ‘<colgroup>‘, you can enhance the structure and styling of your HTML tables, making them more flexible and maintainable.

Leave a Comment