Scroll to top
2 min read

The HTML <col> element defines a column within a table, and is often used in combination with the <colgroup> element. It is used to apply properties to all cells in a specific column of a table.

Syntax

1
<col attribute1="value1" attribute2="value2"...>

Example

This example shows the usage of the <col> element within a table.

1
<table>
2
  <colgroup>
3
    <col style="width: 300px">
4
    <col>
5
    <col>
6
  </colgroup>
7
  <thead>
8
    <tr>
9
      <th>Product Name</th>
10
      <th>Description</th>
11
      <th>Price</th>
12
    </tr>
13
  </thead>
14
  <tbody>
15
    <tr>
16
      <td>Product 1</td>
17
      <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam euismod, nunc quis bibendum varius, metus urna hendrerit augue, id congue purus odio id lectus.</td>
18
      <td>$9.99</td>
19
    </tr>
20
    <tr>
21
      <td>Product 2</td>
22
      <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam euismod, nunc quis bibendum varius, metus urna hendrerit augue, id congue purus odio id lectus.</td>
23
      <td>$14.99</td>
24
    </tr>
25
    <tr>
26
      <td>Product 3</td>
27
      <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam euismod, nunc quis bibendum varius, metus urna hendrerit augue, id congue purus odio id lectus.</td>
28
      <td>$19.99</td>
29
    </tr>
30
  </tbody>
31
</table>

Result

Notice how the first column in the table is always 300px wide, no matter how wide the table is. Check the full page demo to see more clearly.

Please accept marketing cookies to load this content.

Attributes

The <col> tag supports Global Attributes in HTML. Global Attributes are common to all HTML elements and can be used on all of them (though they may not have much of an effect on some of them).

The <col> element has the following attributes:

  • span: specifies the number of columns a <col> element should span.

Content

The <col> element does not accept any content.

Tables and tabular data are hugely important for web pages. HTML gives us a large number of elements for structuring tables.