HTML <col> tag

The <col> tag is used to set properties for the columns in a column group. This is useful in tables when you want to set a similar style to all of the cells in a table row but don't want to repeat the same style for each cell individually.

Attributes

Attribute Possible values Description
align left, center, right, justify, char Sets the horizontal alignment of content inside a column in a column group
char theCharacter Specifies a character within a column to which the content within the column will be aligned to
charoff numCharacters Specifies the number of characters the content in a column will be aligned from the character set with the char attribute
span numColumns Specifies how many columns in a column group to set properties for.
valign top, middle, bottom, baseline Sets the vertical alignment of content inside a column in a column group
width numericValue OR % of sorrounding element Sets the width of a column

NOTE: Some of the attributes of the <col> tag have bad browser support. The align attribute - supported only by Internet Explorer and Opera. The char and charoff attributes - not supported by any of the major browsers.

Standard attributes

class, dir, id, lang, style, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

For more information on event attributes, check out our HTML event attributes reference page.

Use the span attribute to set properties for more than one column in a column group.

Example

<table border="2" cellspacing="5" cellpadding="2"> <col align="center" valign="top" width="55%" span="4"></col> <col align="center"></col> <tr> <th>Subject</th> <th>Description</th> </tr> <tr> <td>Math</td> <td>Learn about things like squares and formulas</td> </tr> <tr> <td>Literature</td> <td>Read and analyze characters, settings, and much more</td> </tr> <tr> <td>Computer Science</td> <td>Find out how to tweak those crazy computers!</td> </tr> </table>
Output:
Subject Description
Math Learn about things like squares and formulas
Literature Read and analyze characters, settings, and much more
Computer Science Find out how to tweak those crazy computers!

Tips & notes

Use CSS to set styles for columns in a column group.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation