Tag <col> HTML Reference



Example

Set the background color of the three columns with the <colgroup> and <col> tags:

<table border="1">
  <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>

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

1. Definition and Usage

The <col> tag defines attribute values for one or more columns in a table.

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

The <col> tag can only be used inside a <table> or a <colgroup> element.


2. Tips and Notes

Tip: Add the style attribute to the <col> tag, and let CSS take care of backgrounds, width and borders.

Also have a look at the <colgroup> tag.


3. Differences Between HTML 4.01 and HTML5

Most of the attributes in HTML 4.01 are not supported in HTML5.


4. Differences Between HTML and XHTML

In HTML the <col> tag has no end tag.

In XHTML, the <col> tag must be properly closed.


5. Optional Attributes

DTD indicates in which HTML 4.01/XHTML 1.0 DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.

Attribute Value Description DTD
align left
right
center
justify
char
Specifies the alignment of the content related to a <col> element STF
char character Specifies the alignment of the content related to a <col> element to a character STF
charoff number Specifies the number of characters the content will be aligned from the character specified by the char attribute STF
span number Specifies the number of columns a <col> element should span STF
valign top
middle
bottom
baseline
Specifies the vertical alignment of the content related to a <col> element STF
width %
pixels
relative_length
Specifies the width of a <col> element STF

6. Standard Attributes

The <col> tag supports the Standard Attributes in HTML.


7. Event Attributes

The <col> tag also supports the Standard Event Attributes in HTML.


Relative articles