Live Preview
A three-column table with different column backgrounds:
| Name | Score | Grade |
|---|---|---|
| Alex | 92 | A |

By the end of this tutorial, you’ll style table columns efficiently with <col> inside <colgroup>.
Place <col> inside <colgroup> within a table.
Apply background colors and widths to entire columns at once.
Style multiple adjacent columns with a single col rule.
Understand the container and child relationship.
Replace the obsolete HTML width attribute with CSS.
Pair column styling with caption and proper headers.
<col> Tag?The col element (<col>) specifies column-level presentation for an HTML table. Each col maps to one or more vertical columns, letting you style them from a single place in the markup.
Valid HTML requires <col> elements as children of <colgroup>, which sits inside <table>.
Common uses include zebra-stripe columns, highlighting totals columns, setting consistent widths, and applying column backgrounds in reports and dashboards.
Place <col> elements inside <colgroup>, which goes inside <table>:
<table>
<colgroup>
<col span="2" style="background:#f8fafc">
<col style="background:#eff6ff">
</colgroup>
<thead>
<tr><th>Col 1</th><th>Col 2</th><th>Col 3</th></tr>
</thead>
<tbody>
<tr><td>Data</td><td>Data</td><td>Data</td></tr>
</tbody>
</table><col> is a void element—no closing tag in HTML5.colgroup, after caption and before thead/tbody.span to apply one rule to multiple adjacent columns.col—not the obsolete HTML width attribute.| Use Case | Code Snippet | Result |
|---|---|---|
| Single column | <col style="background:#f1f5f9"> | One column styled |
| Multiple columns | <col span="2" style="..."> | Two adjacent columns share the rule |
| Column width | <col style="width:40%"> | Use with table-layout: fixed |
| Parent element | <colgroup><col></colgroup> | Required valid structure |
| Obsolete width | width="100" on col | Do not use—use CSS |
| Tag-specific attrs | span | Plus global attributes |
<col> vs <colgroup>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 attribute | Supported on colgroup too | Most common on col |
| Learn next | Groups multiple cols | Individual column rules |
Important <col> attributes for beginners:
span Tag-specificNumber of adjacent columns this col element affects.
span="2"class GlobalCSS hook for column background, width, and visibility.
class="col-total"style GlobalInline CSS for background-color and width on the column.
style="background:#eff6ff"width ObsoleteHTML width attribute is obsolete—use CSS width instead.
/* use CSS */Element type VoidNo closing tag in HTML5; self-closing in XHTML.
<col>Parent RequiredMust be a child of colgroup inside table.
<colgroup><col>Use CSS width on col with table-layout: fixed on the table for predictable column sizing.
Column backgrounds, widths, and span rules with copy-ready code and live table previews.
A three-column table with different column backgrounds:
| Name | Score | Grade |
|---|---|---|
| Alex | 92 | A |
A valid structure with colgroup and two col rules—one using span.
<table>
<colgroup>
<col span="2" style="background:#f8fafc">
<col style="background:#eff6ff">
</colgroup>
<tr><th>Col 1</th><th>Col 2</th><th>Col 3</th></tr>
<tr><td>A</td><td>B</td><td>C</td></tr>
</table>Use <col> to zebra-stripe columns, highlight totals columns, set consistent widths, or apply column backgrounds in reports and dashboards.
Give each column its own background with one col per column.
<colgroup>
<col style="background:#fef9c3">
<col style="background:#dcfce7">
</colgroup>Set column widths using CSS on col and table-layout: fixed on the table.
table {
table-layout: fixed;
width: 100%;
}
col:nth-child(1) { width: 30%; }
col:nth-child(2) { width: 70%; }Apply one col rule to multiple adjacent columns with span.
<colgroup>
<col span="3" style="background:#f0fdf4">
<col style="background:#fef2f2">
</colgroup>Apply column backgrounds and widths through CSS on col elements:
background Column highlightwidth Fixed proportionsspan Multi-column ruletable-layout Fixed table layout/* Column background colors */
col.highlight {
background: #eff6ff;
}
/* Column widths with fixed layout */
table {
table-layout: fixed;
width: 100%;
}
col.col-narrow { width: 30%; }
col.col-wide { width: 70%; }Live styled column table
| SKU | Product Name |
|---|---|
| A12 | Wireless keyboard |
Column styling supports readable tables, but accessibility depends on structure:
th and scope — col styling does not replace proper headers.caption — describe what the table shows.Define column rules before table body rows.
Each col applies to one or more vertical columns via span.
Background and width affect every cell in that column.
Style entire columns from one place instead of repeating classes on every td.
The <col> element is supported in all browsers, including Internet Explorer.
From legacy Internet Explorer to the latest mobile browsers — the col element is fully supported for column-level table presentation.
Bottom line: Ship styled data tables with confidence. The <col> element is safe to use in every production environment today.
The <col> tag helps you style table columns efficiently. Always place it inside <colgroup>, use span for multi-column rules, and prefer CSS over the obsolete width attribute.
Pair column styling with accessible table structure—caption, proper th headers, and sufficient color contrast.
col elements in colgroupspan to style multiple columns at oncetable-layout: fixedcaption and proper th headerscol directly inside table without colgroupwidth HTML attribute<col>Bookmark these before you ship — they’ll keep your table columns clean and maintainable.
<col> applies default styles to entire table columns.
Must live inside colgroup as a valid child of table.
One col rule can affect multiple adjacent columns.
ReferenceNo closing tag in HTML5—self-closing in XHTML.
SyntaxUse CSS width, not the obsolete HTML width attribute.
Combine with caption and colgroup for full table structure.
col elements to be children of colgroup.col element applies to. span="3" styles the next three columns.width on col with table-layout: fixed.colgroup is the container; col is the child that styles individual columns inside it.Practice colgroup, col, and the span attribute in the interactive editor.
6 people found this page helpful