Live Preview
A table with <colgroup> and colored columns:
| Product | Qty |
|---|---|
| Notebooks | 24 |

By the end of this tutorial, you’ll group table columns and organize column-level styling with <colgroup>.
Place <colgroup> inside <table> with col children.
Organize column definitions in one structured block.
Count columns in a group when no col children exist.
Understand container vs individual column rules.
Apply backgrounds and widths through child col elements.
Pair column groups with caption and proper headers.
<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.
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.
Place <colgroup> inside <table> with one or more <col> children:
<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><colgroup> is a table structural element—not visible on its own.caption (if any) and before row content.col children inside for per-column styling rules.span on empty colgroup to count columns without col children.| Use Case | Code Snippet | Result |
|---|---|---|
| With col children | <colgroup><col></colgroup> | Standard column grouping |
| Empty group + span | <colgroup span="2"></colgroup> | Two columns in the group |
| Column styling | CSS on child col | Background and width on columns |
| Table placement | After caption, before thead | Valid early table position |
| Pair with caption | <caption> + colgroup | Accessible table structure |
| Tag-specific attrs | span | Plus global attributes |
<colgroup> vs <col>These elements work together to define column presentation:
| Feature | <colgroup> | <col> |
|---|---|---|
| Role | Container for column definitions | Styles one or more columns |
| Placement | Direct child of table | Child of colgroup |
| span on colgroup | When no col children | Counts columns in the group |
| span on col | With col children present | Styles multiple adjacent columns |
Important <colgroup> attributes for beginners:
span Tag-specificColumn count when colgroup has no col children.
span="2"class GlobalCSS hook for grouping or targeting column sets.
class="data-cols"style GlobalLimited effect—prefer styling child col elements.
style="..."Children colOptional col elements define per-column rules.
<col>Parent RequiredMust be a direct child of table.
<table><colgroup>Position EarlyAfter caption, before thead/tbody/tr.
caption → colgroup → rowsWhen you use col children, put span on col for multi-column styling—not redundantly on both colgroup and every col.
Colgroup structure, column widths, backgrounds, and span grouping with copy-ready code and live table previews.
A table with <colgroup> and colored columns:
| Product | Qty |
|---|---|
| Notebooks | 24 |
A three-column table with one colgroup and three col rules.
<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>Use <colgroup> for reports, pricing tables, schedules, and dashboards where you want consistent column widths or backgrounds without styling every cell individually.
Set proportional widths on col inside colgroup with table-layout: fixed.
<colgroup>
<col style="width:30%">
<col style="width:70%">
</colgroup>Use readable pastel backgrounds on col elements—not harsh colors that hurt contrast.
<colgroup>
<col style="background:#fef9c3">
<col style="background:#dcfce7">
</colgroup>Use span on empty colgroup elements to define column groups without individual col rules.
<colgroup span="2"></colgroup>
<colgroup span="2"></colgroup>
<!-- Four columns in two groups of two -->Apply column presentation through CSS on child col elements inside colgroup:
background Column highlightwidth Fixed proportionscolgroup span Group column counttable-layout Fixed table layout/* 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
| Code | Product Name |
|---|---|
| SKU-01 | Wireless keyboard |
colgroup helps presentation, but accessible tables need structure too:
caption — describe what the table contains.th with scope — column styling does not replace headers.Place it after caption, before row content.
Each col maps to one or more vertical columns.
Width and background cascade to cells in each column.
Column rules live in one block instead of repeated cell classes.
The <colgroup> element is supported in all browsers, including Internet Explorer.
From legacy Internet Explorer to the latest mobile browsers — the colgroup element is fully supported for organizing table columns.
Bottom line: Ship organized table columns with confidence. The <colgroup> element is safe to use in every production environment today.
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.
col elements inside colgroupcolcolgroup before table body rowscaption and th scopespan on colgroup and every colfont-weight on col to always work<colgroup>Bookmark these before you ship — they’ll keep your table column markup organized and maintainable.
<colgroup> groups one or more table columns together.
Child col elements define per-column styling rules.
Counts columns when no col children are present.
Goes inside table, after caption and before rows.
Background and width CSS work best on child col elements.
Combine with caption and col for full table structure.
col elements.colgroup is the container; col is the child that styles individual columns inside it.col children, span sets how many columns belong to that group.table, after caption (if present) and before thead, tbody, or tr.col inside colgroup. You can also style th and td with CSS, but colgroup is the semantic column approach.Practice colgroup and col together in the interactive HTML editor.
6 people found this page helpful