HTML <col> Tag
<col> tag is used for specifying column properties for each column within a
<col> tag can be handy if you need to specify styles across one or more columns. Rather than apply the styles at the individual
<td> level, you can apply it to the
<col> element. Then all
<th>) elements contained within that
<col> will be styled accordingly.
Note: You can only apply 4 CSS properties to table columns. See "CSS Limitation" below for more information.
<col> tag is written as
<col> (no end tag). You can use the
span attribute to specify the number of columns to span.
The tag be used within a
<colgroup> tag that doesn't have a
Basic tag usage
Here we apply a different background color to the columns using the
<col> tag in conjunction with the CSS
Attributes can be added to an HTML element to provide more information about how the element should appear or behave.
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes.
<col> element accepts the following attributes.
This table shows the attributes that are specific to the
|span||Specifies how many columns to span. This attribute's value must be a valid non-negative integer greater than zero.|
The following attributes are standard across all HTML5 elements. Therefore, you can use these attributes with the
<col> tag , as well as with all other HTML tags.
For a full explanation of these attributes, see HTML 5 global attributes.
Event Handler Content Attributes
Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.
Below are the standard HTML5 event handler content attributes.
Again, you can use any of these with the
<col> element, as well as any other HTML5 element.
For a full explanation of these attributes, see HTML 5 event handler content attributes.
Differences Between HTML 4 & HTML 5
valign attributes (which were supported in HTML 4) have been made obsolete in HTML5.
To see more detail on the two versions see HTML5
<col> Tag and HTML4
<col> Tag. Also check out the links to the official specifications below.
There are only four CSS properties that can be applied to column and column-group elements. They are as follows:
- The various border properties apply to columns only if
border-collapseis set to
collapseon the table element. In that case, borders set on columns and column groups are input to the conflict resolution algorithm that selects the border styles at every cell edge.
- The background properties set the background for cells in the column, but only if both the cell and row have transparent backgrounds.
- Provides the minimum width for the column.
- If the
visibilityof a column is set to
collapse, none of the cells in the column are rendered, and cells that span into other columns are clipped. In addition, the width of the table is diminished by the width the column would have taken up.
Taken from the CSS 2.1 specification
And in case you're interested, here's the reasoning behind why only four CSS properties can be applied to table columns.
Here's a template for the
<col> tag with all available attributes for the tag (based on HTML5). These are grouped into attribute types, each type separated by a space. In many cases, you will probably only need one or two (if any) attributes. Simply remove the attributes you don't need.
For more information on attributes for this tag, see HTML5
<col> Tag and HTML4
For more details about the
<col> tag, see HTML5
<col> Tag and HTML4
Here are the official specifications for the
- HTML5 Specification (W3C)
- HTML Living Standard (WHATWG)
- Current W3C Draft (the next version that is currently being worked on)
- HTML 4 (W3C)
What's the Difference?
W3C creates "snapshot" specifications that don't change once defined. So the HTML5 specification won't change once it becomes an official recommendation. WHATWG on the other hand, develops a "living standard" that is updated on a regular basis. In general, you will probably find that the HTML living standard will be more closely aligned to the current W3C draft than to the HTML5 specification.