October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

HTML : How to Group and Style Table Columns

HTML groups consecutive table columns for limited styling. Learn the correct placement, span rules, CSS behavior, accessibility requirements, and common mistakes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The HTML <colgroup> element groups one or more columns in a <table>, primarily so you can style those columns together. Put it after an optional <caption> and before <thead>, <tbody>, <tfoot>, or individual rows. It does not create cells or provide header semantics; use <th>, scope, and a caption for that.

What <colgroup> does

A table’s columns are defined by the cells in its rows. <colgroup> adds a structural layer that lets you describe consecutive columns as a group. This is useful for column backgrounds, minimum widths, borders in collapsed-border tables, and column visibility. It does not add rows, cells, labels, or screen-reader relationships.

See the MDN colgroup reference and MDN table basics for the platform definitions.

Where it belongs in a table

The permitted order is an optional caption, then column groups, then the table’s row groups or rows:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<table>
  <caption>Quarterly revenue by region</caption>
  <colgroup>
    <col class="region-column">
    <col span="2" class="quarter-columns">
  </colgroup>
  <thead>
    <tr>
      <th scope="col">Region</th>
      <th scope="col">Q1</th>
      <th scope="col">Q2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">North</th>
      <td>120</td>
      <td>135</td>
    </tr>
  </tbody>
</table>

In this example, the first <col> describes column one. The second describes the next two columns because its span is 2. Column positions are determined by the table’s columns, not by text appearing inside the cells.

Two ways to describe columns

Choose either a span on an otherwise empty <colgroup>, or child <col> elements. A <colgroup> with child columns must not also have its own span attribute.

Approach Example Best when
Group-level span <colgroup span="3"></colgroup> Several adjacent columns share one treatment and need no separate classes.
Child <col> elements <colgroup><col><col span="2"></colgroup> Different column groups need distinct classes, styles, or spans.

The span value is a positive integer greater than zero. If a <col> has no span, its default is 1. This is the valid group-level form:

<table>
  <colgroup span="3" class="numeric-columns"></colgroup>
  <tr><td>A</td><td>B</td><td>C</td></tr>
</table>

Do not write <colgroup span="3"><col>...</colgroup>; when child <col> elements are present, the group-level span is not permitted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What CSS can style

Column groups intentionally support a narrow set of CSS effects. MDN documents background properties, borders when the table uses border-collapse: collapse, visibility: collapse, and width. On a column group, width acts as a minimum width for the grouped columns.

table {
  border-collapse: collapse;
}

.region-column {
  background: #eef;
}

.quarter-columns {
  background: #efe;
}

Backgrounds are painted behind backgrounds on columns, row groups, rows, and cells. An opaque <td> or <th> background can therefore hide the color applied to <colgroup> or <col>. If you need text alignment, typography, padding, or another property that column groups do not affect, style the <th> and <td> cells instead.

Hiding a column group

visibility: collapse is the column-group behavior documented by MDN for collapsing columns. Test the result in the browsers that matter to your application, especially when the table includes spanning cells. Do not confuse this with a class name or a background-color example: a colored column is not hidden.

Cell selectors as an alternative

For tables without colspan, positional selectors such as td:nth-of-type() can target cells directly. Once colspan is involved, positional matching requires more careful selectors because one cell can occupy multiple columns. Use a column group when the styling is genuinely column-wide, and cell selectors when the desired property is not supported on columns.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Column styling is not table accessibility

Give the table a concise <caption> that states its purpose. Use <th> for header cells and set scope="col" for column headers or scope="row" for row headers when the relationships are straightforward. These elements provide meaning and navigation cues; <colgroup> only groups columns for structure and styling.

<table>
  <caption>Support tickets by priority</caption>
  <colgroup><col class="priority"></colgroup>
  <thead>
    <tr>
      <th scope="col">Priority</th>
      <th scope="col">Open</th>
    </tr>
  </thead>
  ...
</table>

A caption and header cells help people understand the data; adding a <colgroup> alone does not improve accessibility or establish those header relationships.

Common mistakes and fixes

  • Putting the element after the header: move <colgroup> before <thead>, <tbody>, <tfoot>, and rows.
  • Combining group span with child columns: remove the group-level attribute or remove the child <col> elements.
  • Expecting arbitrary CSS to cascade to cells: apply unsupported properties directly to <th> and <td>.
  • Not seeing a background: inspect cell, row, and column backgrounds; an opaque cell background is painted over the group.
  • Using it as a header: keep the semantic header in <th> and use scope where appropriate.
  • Counting columns incorrectly: account for every <col> span and for cells that use colspan.

Is <colgroup> still valid?

Yes. MDN marks the element as widely available across browsers since July 2015. That is general compatibility guidance, not a guarantee that every complex combination of spanning, collapsing, and CSS rendering will look identical everywhere. Test unusual layouts in your supported browsers.

When to use it

  • Use <colgroup> when several adjacent columns share a background, minimum width, border treatment, or collapse behavior.
  • Use separate <col> elements when columns need different classes or spans.
  • Use direct cell styling when you need alignment, padding, fonts, or other properties outside the column-group set.
  • Always retain captions and header cells for the table’s meaning and accessible navigation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.