English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: <col> Tag

HTML <col> element defines the columns in the table and is used to define the common semantics on all common cells. It is usually located within the <colgroup> element.

Online Example

The <colgroup> and <col> tags set the background color for three columns in the table:

!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic Tutorial Website(oldtoolbag.com)</title> 
</head>
<body>
<table>
  <colgroup>
    <col span="3" style="background-color:#FFF3E0;">
    <col style="background-color:orange;">
  </colgroup>
  <thead>
    <tr>
      <th>Item</th>
      <th>Quantity</th>
      <th>Price</th>
      <th>Total</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Oranges</td>
      <td>45</td>
      <td>$2</td>
      <td>$90</td>
    </tr>
  </tbody>
</table>
</body>
</html>
Test to see ‹/›


In this HTML5In the document example, we created a table with <colgroup>, <thead>, and <tbody> sections. In the <colgroup> section, we used two <col> tags. The first <col> tag groups the first three columns and sets the background color of these columns to light orange, that is, #FFF3The hexadecimal value of E0. The second <col> tag groups the fourth column and sets its background color to orange.

Browser Compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the <col> tag.

Tag Definition and Usage Instructions

The <col> tag is used for<colgroup>Part, to define the column properties.

By using the <col> tag, you can apply styles to the entire column without having to repeat the styles for each cell or each row.

HTML 4.01 And HTML5The Differences Between

HTML5 No longer supports HTML 4.01 Most of the attributes.

The Differences Between HTML and XHTML

In HTML, the <col> tag does not have a closing tag.

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

Attribute

AttributeValueDescription
alignleft
 right
 center
 justify
 char
HTML5 Not supported. Defines the horizontal alignment of the content related to the <col> element.
charcharacterHTML5 Not supported. Defines which character to align the content related to the <col> element by.
charoffnumberHTML5 Not supported. Defines the offset of the first alignment character.
spannumberSpecifies the number of columns that the <col> element should span.
valigntop
 middle
 bottom
 baseline
HTML5 Not supported. Defines the vertical alignment of the content related to the <col> element.
width%
 pixels
 relative_length
HTML5 Not supported. Specifies the width of a <col> element

Global Attributes

Support for <col> tag Global Attributes of HTML.

Event Attributes

Support for <col> tag HTML Event Attributes.