HTML <colgroup> Tag

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Tables

What You’ll Learn

By the end of this tutorial, you’ll group table columns and organize column-level styling with <colgroup>.

01

Colgroup Syntax

Place <colgroup> inside <table> with col children.

02

Column Grouping

Organize column definitions in one structured block.

03

span Attribute

Count columns in a group when no col children exist.

04

colgroup vs col

Understand container vs individual column rules.

05

Column Styling

Apply backgrounds and widths through child col elements.

06

Accessible Tables

Pair column groups with caption and proper headers.

What Is the <colgroup> Tag?

The colgroup element (<colgroup>) represents a group of one or more columns in a table. It does not render visible content by itself—it organizes column definitions, usually through child <col> elements.

💡
Container for col elements

Place <colgroup> inside <table>, after caption and before thead/tbody. Put styling rules on child col elements.

Common uses include reports, pricing tables, schedules, and dashboards where you want consistent column widths or backgrounds without styling every cell individually.

📝 Syntax

Place <colgroup> inside <table> with one or more <col> children:

syntax.html
<table>
  <colgroup>
    <col style="background:#f8fafc">
    <col style="background:#eff6ff">
  </colgroup>
  <thead>
    <tr><th>Name</th><th>Score</th></tr>
  </thead>
  <tbody>
    <tr><td>Alex</td><td>92</td></tr>
  </tbody>
</table>

Syntax Rules

  • <colgroup> is a table structural element—not visible on its own.
  • Place it after caption (if any) and before row content.
  • Put col children inside for per-column styling rules.
  • Use span on empty colgroup to count columns without col children.

⚡ Quick Reference

Use CaseCode SnippetResult
With col children<colgroup><col></colgroup>Standard column grouping
Empty group + span<colgroup span="2"></colgroup>Two columns in the group
Column stylingCSS on child colBackground and width on columns
Table placementAfter caption, before theadValid early table position
Pair with caption<caption> + colgroupAccessible table structure
Tag-specific attrsspanPlus global attributes

⚖️ <colgroup> vs <col>

These elements work together to define column presentation:

Feature<colgroup><col>
RoleContainer for column definitionsStyles one or more columns
PlacementDirect child of tableChild of colgroup
span on colgroupWhen no col childrenCounts columns in the group
span on colWith col children presentStyles multiple adjacent columns

🧰 Attributes

Important <colgroup> attributes for beginners:

span Tag-specific

Column count when colgroup has no col children.

span="2"
class Global

CSS hook for grouping or targeting column sets.

class="data-cols"
style Global

Limited effect—prefer styling child col elements.

style="..."
Children col

Optional col elements define per-column rules.

<col>
Parent Required

Must be a direct child of table.

<table><colgroup>
Position Early

After caption, before thead/tbody/tr.

caption → colgroup → rows

When you use col children, put span on col for multi-column styling—not redundantly on both colgroup and every col.

Examples Gallery

Colgroup structure, column widths, backgrounds, and span grouping with copy-ready code and live table previews.

Live Preview

A table with <colgroup> and colored columns:

ProductQty
Notebooks24

Basic colgroup with col

A three-column table with one colgroup and three col rules.

basic-colgroup.html
<table>
  <colgroup>
    <col style="width:35%;background:#f8fafc">
    <col style="width:35%;background:#f8fafc">
    <col style="width:30%;background:#eff6ff">
  </colgroup>
  <tr><th>First</th><th>Second</th><th>Third</th></tr>
  <tr><td>A</td><td>B</td><td>C</td></tr>
</table>
Try It Yourself

📚 Common Use Cases

Use <colgroup> for reports, pricing tables, schedules, and dashboards where you want consistent column widths or backgrounds without styling every cell individually.

Column Widths

Set proportional widths on col inside colgroup with table-layout: fixed.

column-widths.html
<colgroup>
  <col style="width:30%">
  <col style="width:70%">
</colgroup>
Try It Yourself

Column Background Colors

Use readable pastel backgrounds on col elements—not harsh colors that hurt contrast.

column-colors.html
<colgroup>
  <col style="background:#fef9c3">
  <col style="background:#dcfce7">
</colgroup>
Try It Yourself

colgroup span (No col Children)

Use span on empty colgroup elements to define column groups without individual col rules.

colgroup-span-groups.html
<colgroup span="2"></colgroup>
<colgroup span="2"></colgroup>
<!-- Four columns in two groups of two -->
Try It Yourself

Styling <colgroup> and <col> with CSS

Apply column presentation through CSS on child col elements inside colgroup:

background Column highlight
width Fixed proportions
colgroup span Group column count
table-layout Fixed table layout
colgroup-styles.css
/* Style columns inside colgroup */
colgroup col.highlight {
  background: #eff6ff;
}

table {
  table-layout: fixed;
  width: 100%;
}

colgroup col.col-narrow { width: 30%; }
colgroup col.col-wide   { width: 70%; }

Live styled colgroup table

♿ Accessibility

colgroup helps presentation, but accessible tables need structure too:

  • Add caption — describe what the table contains.
  • Use th with scope — column styling does not replace headers.
  • Maintain contrast — column backgrounds must keep text readable.
  • Do not rely on color alone — labels must convey meaning.

🧠 How <colgroup> Works

1

Author adds colgroup in table

Place it after caption, before row content.

Markup
2

col elements define columns

Each col maps to one or more vertical columns.

Grouping
3

Browser applies column styles

Width and background cascade to cells in each column.

Rendering
=

Organized, styled tables

Column rules live in one block instead of repeated cell classes.

Universal Browser Support

The <colgroup> element is supported in all browsers, including Internet Explorer.

Baseline · Since HTML 4

Column grouping that works everywhere

From legacy Internet Explorer to the latest mobile browsers — the colgroup element is fully supported for organizing table columns.

100% Core tag support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
<colgroup> tag 100% supported

Bottom line: Ship organized table columns with confidence. The <colgroup> element is safe to use in every production environment today.

Conclusion

The <colgroup> tag organizes column definitions in HTML tables. Pair it with <col> for styling, use span correctly on colgroup or col, and combine with caption and proper headers.

Column grouping keeps your table markup DRY—one structured block instead of repeated styling on every cell.

💡 Best Practices

✅ Do

  • Put col elements inside colgroup
  • Use background and width CSS on col
  • Place colgroup before table body rows
  • Pair with caption and th scope

❌ Don’t

  • Mix redundant span on colgroup and every col
  • Expect font-weight on col to always work
  • Use harsh colors that break text contrast
  • Skip table headers because columns are colored

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <colgroup>

Bookmark these before you ship — they’ll keep your table column markup organized and maintainable.

6
Core concepts
📝 02

Contains col

Child col elements define per-column styling rules.

Essential
🔢 03

span on colgroup

Counts columns when no col children are present.

Reference
📋 04

Early Placement

Goes inside table, after caption and before rows.

Syntax
🎨 05

Style via col

Background and width CSS work best on child col elements.

Styling
🔗 06

Works with caption

Combine with caption and col for full table structure.

Pattern

❓ Frequently Asked Questions

It groups columns in a table so you can define column-level presentation, usually through child col elements.
colgroup is the container; col is the child that styles individual columns inside it.
When there are no col children, span sets how many columns belong to that group.
Inside table, after caption (if present) and before thead, tbody, or tr.
Valid HTML requires col inside colgroup. You can also style th and td with CSS, but colgroup is the semantic column approach.

Group Table Columns

Practice colgroup and col together in the interactive HTML editor.

Try colgroup + col →

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.

6 people found this page helpful