HTML <colgroup> Tag

Beginner
7 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <colgroup> element defines a group of columns in a <table>. Use it to style or size several columns together.

Two valid patterns: set span on <colgroup> with no <col> children, or omit span and nest one or more <col> elements. Place <colgroup> after any <caption> and before <thead>, tbody, tfoot, or tr.

Baseline · Widely available.

Not deprecated as an element. Stable across browsers since about July 2015 (and earlier in practice). Some CSS effects on column groups have limits.

Deprecated attributes.

Do not use align, bgcolor, char, charoff, valign, or width on <colgroup>. Use CSS instead.

HTML Syntax

syntax.html
<colgroup span=" n"></colgroup>

Or nest columns: <colgroup><col>…</colgroup> with no span on the group. Keep both start and end tags in study examples for clarity.

Attributes

Modern and legacy attributes you may see on <colgroup>:

AttributeDescriptionTry it
spanHow many consecutive columns this group covers. Positive integer; default 1. Not allowed when the group contains <col>.Try it
widthDeprecated — use CSS width insteadTry it
alignDeprecated — use CSS text-align insteadTry it
valignDeprecated — use CSS vertical-align insteadTry it
bgcolorDeprecated — use CSS background-color insteadTry it
char / charoffDeprecated — use CSS text-align (and tabular numerals) insteadTry it

Global Attributes

The <colgroup> tag also supports the Global Attributes in HTML.

Live Preview

Toggle which column group is highlighted using real <colgroup span> elements.

Group backgrounds show when cell backgrounds are transparent.

Table
MonTueWedThuFriSatSun
StudyGymClassLabShopRestFree

Weekdays group highlighted (span="5")

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Groups with span (No col Children)

Two <colgroup> elements cover weekdays and weekend with span.

HTML
<style>
  .weekdays { background-color: #dbeafe; }
  .weekend { background-color: #fef9c3; }
</style>

<table>
  <colgroup span="5" class="weekdays"></colgroup>
  <colgroup span="2" class="weekend"></colgroup>
  <tr>
    <th>Mon</th><th>Tue</th><th>Wed</th>
    <th>Thu</th><th>Fri</th>
    <th>Sat</th><th>Sun</th>
  </tr>
  <tr>
    <td>Study</td><td>Gym</td><td>Class</td>
    <td>Lab</td><td>Shop</td>
    <td>Rest</td><td>Free</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. First group uses span="5" for Mon–Fri.
  2. Second group uses span="2" for Sat–Sun.
  3. No <col> inside these groups — span owns the count.
  4. CSS classes color each group; keep cell backgrounds transparent.

Example 2 — colgroup with Nested col

Omit span on the group and define columns with <col>.

HTML
<style>
  .label { background-color: #f8fafc; }
  .data { background-color: #eff6ff; }
</style>

<table>
  <colgroup>
    <col class="label">
    <col span="2" class="data">
  </colgroup>
  <tr>
    <th scope="col">Item</th>
    <th scope="col">Q1</th>
    <th scope="col">Q2</th>
  </tr>
  <tr>
    <td>Books</td>
    <td>12</td>
    <td>18</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Open <colgroup> without span so it may contain <col>.
  2. First <col> styles the label column.
  3. Second <col span="2"> styles Q1 and Q2 together.
  4. Do not set span on the parent group when col children exist.

Example 3 — Order: caption, then colgroup

Put <colgroup> after <caption> and before header rows.

HTML
<table>
  <caption>Team scores</caption>
  <colgroup span="1"></colgroup>
  <colgroup span="2" class="scores"></colgroup>
  <thead>
    <tr>
      <th scope="col">Team</th>
      <th scope="col">Wins</th>
      <th scope="col">Losses</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alpha</td>
      <td>4</td>
      <td>1</td>
    </tr>
  </tbody>
</table>

<style>
  .scores { background-color: #dcfce7; }
</style>
Try It Yourself

How It Works

  1. Caption first (optional title for the table).
  2. Then colgroup — never after thead or body rows.
  3. Then structure with thead / tbody.
  4. Style the score group with a class on the second colgroup.

Example 4 — Several Groups in One Table

Combine a single label column with styled data groups (MDN-style schedule).

HTML
<style>
  .period { background-color: #f8fafc; }
  .am { background-color: #eff6ff; }
  .pm { background-color: #fef9c3; }
</style>

<table>
  <colgroup>
    <col class="period">
    <col span="3" class="am">
    <col span="3" class="pm">
  </colgroup>
  <tr>
    <th>Day</th>
    <th>9</th><th>10</th><th>11</th>
    <th>1</th><th>2</th><th>3</th>
  </tr>
  <tr>
    <th scope="row">Mon</th>
    <td>Math</td><td>Sci</td><td>PE</td>
    <td>Art</td><td>Hist</td><td>Lab</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. One colgroup hosts all col definitions (no group-level span).
  2. Period column gets its own col.
  3. Morning hours share span="3"; afternoon hours share another span="3".
  4. 1 + 3 + 3 = 7 matches seven cells per row.

Edge Cases & Pitfalls

Most colgroup bugs mix span with col, wrong order, or covered backgrounds.

rules

span XOR nested col

Never combine span on colgroup with <col> children. Choose one pattern.

order

After caption, before rows

Invalid placement (for example after thead) breaks the table model and can confuse browsers.

css

Limited CSS on colgroup

Useful: background, width, visibility: collapse, borders with border-collapse: collapse. text-align on the group does not style cells.

layers

Paint order hides colors

Group backgrounds sit under col, row, and cell backgrounds. Opaque cells hide the group color.

deprecated

Skip presentational attributes

width, align, valign, bgcolor, char, and charoff are obsolete.

Browser Support

The <colgroup> element is core HTML for tables in every modern browser. Prefer CSS over deprecated presentational attributes.

✓ Baseline · Widely available

<colgroup>

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support column groups. CSS background and width on groups are the practical styling hooks.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
<colgroup> Widely supported

Bottom line: Safe to use for grouping columns. Pick either span-on-group or nested col — not both — and style with CSS.

Key Takeaways

  • Role: <colgroup> groups columns for shared styling or sizing.
  • Patterns: span alone, or nested <col> — never both.
  • Order: after caption, before header and body rows.
  • CSS: prefer backgrounds and width; drop deprecated HTML attributes.

One line: place <colgroup> early in the table, then either set span or nest <col> elements.

Default CSS Settings

Typical user-agent mapping for column groups:

default.css
colgroup {
  display: table-column-group;
}

Visible styling comes from the limited CSS you apply to the group (or its col children) and from the cells in those columns.

Frequently Asked Questions

The colgroup element defines a group of columns in a table so you can style or size that group together, either with a span attribute or with nested col elements.
Inside table, after any caption, and before thead, tbody, tfoot, or tr.
No. If colgroup has one or more col children, omit span on colgroup. If you set span on colgroup, it must not contain col elements.
A positive integer for how many consecutive columns the group covers. Default is 1 when span is omitted and there are no col children.
No. Those attributes are deprecated. Use CSS width and style cells with text-align / vertical-align instead.
colgroup groups columns. col defines one or more columns inside a span-free colgroup for finer styling.

Next: comment

Learn HTML comment syntax to leave notes in your markup.

comment tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful