Skip to content

<col> - Table Column Element

Table Element

The <col> element defines a column within a table and is used to apply properties and styles to that column. It must be used inside a <colgroup> element and represents a single column (or multiple consecutive columns when using the span attribute). The <col> element is an empty element—it has no content and doesn’t require a closing tag.

Result
<table>
<colgroup>
<col>
<col style="background-color: yellow;">
<col span="2">
</colgroup>
<!-- table content -->
</table>

The span attribute specifies the number of consecutive columns this <col> element represents. Default is 1.

<col span="3" style="background-color: #f0f0f0;">

This is equivalent to:

<col style="background-color: #f0f0f0;">
<col style="background-color: #f0f0f0;">
<col style="background-color: #f0f0f0;">

The <col> element supports all global HTML attributes.

Result
Result
Result
Result
Result
Result
Result
Result
Result
/* Basic col styling */
col {
background-color: #f0f0f0;
}
/* Width specification */
col {
width: 25%;
}
col.narrow {
width: 10%;
}
col.wide {
width: 50%;
}
/* Background colors */
col.highlight {
background-color: #fff3cd;
}
col.primary {
background-color: #e3f2fd;
}
col.secondary {
background-color: #f3e5f5;
}
/* Borders (requires border-collapse) */
table {
border-collapse: collapse;
}
col {
border-right: 2px solid #333;
}
/* Hiding columns */
col.hidden {
visibility: collapse;
}
/* nth-child selectors */
col:nth-child(odd) {
background-color: #f9f9f9;
}
col:nth-child(even) {
background-color: #ffffff;
}
/* First and last columns */
col:first-child {
background-color: #ecf0f1;
}
col:last-child {
background-color: #fef5e7;
}

Use Within colgroup

Always place <col> elements inside a <colgroup> element.

Match Column Count

Ensure the total span of all <col> elements matches the number of table columns.

Use for Visual Styling

Primarily use <col> for background colors, widths, and borders.

Remember Empty Element

<col> is self-closing—don’t add closing tags or content.

Know CSS Limits

Only use supported CSS properties (background, border, width, visibility).

Test Across Browsers

Some CSS properties may behave differently across browsers.

<!-- ❌ Bad: col is an empty element -->
<col>Column 1</col>
<!-- ✅ Good: no content -->
<col>
<!-- ❌ Bad: color doesn't work on col -->
<col style="color: red; font-weight: bold;">
<!-- ✅ Good: only supported properties -->
<col style="background-color: yellow; width: 30%;">
<!-- ❌ Bad: 3 cols but 4 actual columns -->
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
</tr>
</thead>
<!-- ✅ Good: matching count -->
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
  • Applying background colors to columns
  • Setting consistent column widths
  • Adding borders to specific columns
  • Hiding columns with visibility: collapse
  • Visually grouping columns

The <col> element is supported in all browsers:

  • ✅ Chrome (all versions)
  • ✅ Firefox (all versions)
  • ✅ Safari (all versions)
  • ✅ Edge (all versions)
  • ✅ Opera (all versions)
  • ✅ Internet Explorer (all versions)