Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Reference > HTML Tags > HTML col tag

Bypass main content

HTML col tag

Note: If you don't know what an element/tag is and/or how you must use it we recommend you read our HTML tags and attributes tutorial, which you can find in our HTML tutorials section.

Bypass main content

Description

The HTML col tag is used in tables to provide common attibutes to all the cells in a column or group of columns. It must be inserted right after the starting tag of the HTML table element, and must preserve an order: the first declaration affects the first column, the second declaration affects the second column, and so on.

This order can be affected by the use of the "span" attribute. This attribute can be used in this tag to affect more than one column with the same declaration.

HTML col tags can also be contained by the HTML colgroup tag, when the author needs to define a common set of attributes to columns inside a column group. To learn more about this practice, refer to the "HTML tables" tutorial.

Note, that some attributes available for this tag are purely presentational (align, valign, width, char and charoff), reason for which their use is not recommended. Because of this, the use of the HTML col tag has been reduced, since CSS only supports four properties for it: border, background, width, and visibility.

Examples

The following example shows a common use of the HTML col tag to define the width of columns. Note that in the first declaration, the first and the second columns are affected thanks to the "span" attribute. The properties are set with CSS using the style attribute.

Code
<table>
<col style="width: 180px;" span="2"></col>
<col style="width: 80px; background: #EEEEEE;"></col>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
</tr>
<tr>
<td>Richard</td>
<td>Male</td>
<td>32</td>
</tr>
<tr>
<td>Anna</td>
<td>Female</td>
<td>18</td>
</tr>
<tr>
<td>Dean</td>
<td>Male</td>
<td>23</td>
</tr>
<tr>
<td>Sean</td>
<td>Male</td>
<td>65</td>
</tr>
</table>
View
NameGenderAge
Richard Male 32
Anna Female 18
Dean Male 23
Sean Male 65

Attributes

id (name)

The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element in other instances (e.g., from client-side scripts).

<p id="paragraph1">This is the first paragraph, named "paragraph1". To dynamically change its properties use this identifier.</p>

class (cdata)

The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It is used together with style sheets and tells the browser the class (or classes) to which the element is associated.

A class gives presentational attributes to elements (read more at the Cascading Style Sheets tutorial).

<p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>
<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>

style (style)

This attribute is used to define presentational attributes for the containing element, and its value should be composed by style sheets properties. Although in some cases it can become useful, a better practice is to place presentational attributes in external files, relating them to elements with the "class" attribute. This way you keep the semantic and presentational parts of your document separated.

You can find more information about presentational attributes at the Cascading Style Sheets tutorial.

<p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style.</p>
<p>And this is another text without style.</p>

title (text)

The purpose of this attribute is to provide a title for the element. Its value must be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user puts the mouse pointer over the element for a short period of time.

Code
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a>
View

lang (langcode)

Specifies the language of an element's content. The default value is "unknown".

When writing XHTML 1.0 documents, the attribute used to specify the language of an elements is "xml:lang". For forward and backward compatibility both attributes can be used simultaneously like in the example below. Note that in XHTML 1.1 the "lang" attribute has been completely replaced by "xml:lang" and its use is no longer valid.

<p lang="en" xml:lang="en">This is a paragraph in English.</p>
<p lang="es" xml:lang="es">Este es un párrafo en español.</p>

dir

This attribute indicates the direction in which the texts of the element must be read. This includes content, attribute values and tables. It has two possible values that are case-insensitive:

<q lang="he" dir="rtl">...an Hebrew quotation...</q>

span (number)

This attribute specifies the number of consecutive columns "spanned" or affected by the element or its attributes.

<col span="2" style="border: none;" />
<col span="5" style="background: red;" />

width (multi-length)

This attribute specifies the width for all the cells in the affected columns.

<col width="50" />

align

Sets the alignment for the text inside a cell in the affected columns. It can take one of the following case-insensitive values:

<col align="center" />

valign

Sets the vertical alignment for the text inside a cell in the affected columns. It can take one of the following case-insensitive values:

<col valign="top" />

char (character)

Specifies a single character that will act as axis for text alignment. For its value to be considered, the "align" attribute must be set to "char".

Note that browsers aren't required to support this attribute. This, added to its presentational nature, constitute a good reason not to rely on it.

<col align="char" char="." />

charoff (length)

Specifies an offset for the alignment character (first occurrence) on each line. Text direction, set with the "dir" attribute, must be taken into account to decide which the first occurrence will be.

Note that browsers aren't required to support this attribute. This, added to its presentational nature, constitute a good reason not to rely on it.

<col align="char" char="." charoff="1" />

Events

See a complete list and information about events in HTML

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster