Skip to content

<colgroup> - Table Column Group Element

Table Element

The <colgroup> element defines a group of one or more columns in a table. It allows you to apply styles and attributes to entire columns without having to repeat them for each cell. The <colgroup> must appear after any <caption> but before any table rows (<thead>, <tbody>, <tfoot>, or <tr>).

Result
<table>
<caption>Table caption</caption>
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<!-- table content -->
</thead>
</table>

The <colgroup> must appear in this order:

  1. <caption> (if present)
  2. <colgroup> (if present)
  3. <thead>, <tbody>, <tfoot>, or <tr>

The span attribute specifies how many consecutive columns the <colgroup> represents. This is used when you don’t include individual <col> elements.

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

The <colgroup> element supports all global HTML attributes.

Result
Result
Result

Instead of multiple <col> elements, you can use span:

<colgroup>
<col>
<col>
<col>
</colgroup>
Result
Result
Result
Result
/* Basic colgroup styling */
colgroup {
background-color: #f0f0f0;
}
/* Individual col within colgroup */
colgroup col:nth-child(1) {
background-color: #e3f2fd;
}
colgroup col:nth-child(2) {
background-color: #fff3e0;
}
/* Width specification */
colgroup col {
width: 25%;
}
/* Hiding columns */
colgroup col.hidden {
visibility: collapse;
}
/* Border styling (requires border-collapse) */
table {
border-collapse: collapse;
}
colgroup col {
border-right: 2px solid #333;
}
/* Multiple column groups */
colgroup:nth-of-type(1) {
background-color: #e8f5e9;
}
colgroup:nth-of-type(2) {
background-color: #fff3e0;
}

Use for Column Styling

Use <colgroup> and <col> to apply consistent styles to entire columns.

Place Correctly

Always place <colgroup> after <caption> but before table content.

Match Column Count

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

Know CSS Limitations

Remember only certain CSS properties work on column elements.

Use for Semantic Grouping

Group related columns together for better semantic structure.

Consider Accessibility

While <colgroup> is structural, ensure column relationships are also expressed in headers.

  • Applying the same background color to multiple columns
  • Setting consistent widths for columns
  • Visually grouping related columns
  • Creating alternating column colors
  • Setting borders on specific columns

The <colgroup> 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)