Horje
HTML <col> Tag

The tag specifies column properties for each column within a element.

The tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.


How to create HTML <col> Tag

Set the background color of the three columns with the <colgroup> and <col> tags:
index.html
Example: HTML
 <table>
  <colgroup>
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
</table> 

Output should be:

How to create HTML <col> Tag

What Type of Browsers will Support for HTML <col> Tag

What Type of Browsers will Support for HTML <col> Tag

Attributes for HTML <col> Tag

Attribute Value Description
span number Specifies the number of columns a <col> element should span

How to set Default CSS Settings for HTML <col> Tag

Most browsers will display the <col> element with the following default values:
index.html
Example: HTML
<style>
table, th, td {
  border: 1px solid black;
}

col {
  display: table-column;
} 
</style>

Output should be:

How to set Default CSS Settings for HTML <col> Tag

How to add HTML <col> span Attribute

Here, the first two columns should have a background color of red.

Definition and Usage

The span attribute defines the number of columns a <col> element should span.


Browser Support

Syntax

<col span="number">

Attribute Values

Value Description
number Sets the number of columns a <col> element should span
index.html
Example: HTML
<table>
  <colgroup>
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
  <tr>
    <td>5869207</td>
    <td>My first CSS</td>
    <td>$49</td>
  </tr>
</table>

Output should be:

How to add HTML <col> span Attribute





Category:
Web Tutorial
Sub Category:
HTML Tag
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference