HTML & Web Development 7. HTML Tables 11 mins read 14,105 views

HTML Colgroup Tag: Structure, Attributes, and Examples

The HTML (column group) element specifies formatting and styles for entire columns in a table without repeating CSS classes across hundreds of individual cell...
Published: Nov 1, 2026Last Updated: Nov 21, 2026Curriculum: Class 12 / AP Physics / JEE-NEETReviewed by: OperateTools Editorial Board
Quick Summary & Direct Answer (AEO / GEO Extraction)

What is HTML Colgroup Tag: Structure, Attributes, and Examples? The HTML (column group) element specifies formatting and styles for entire columns in a table without repeating CSS classes across hundreds of individual cell...

Audience & Scope: Students, educators, and candidates preparing for academic examinations and technical assessments in Html & Web Development.
What is the HTML <colgroup> tag and how does it style entire table columns efficiently?
The HTML <colgroup> (column group) element specifies formatting and styles for entire columns in a table without repeating CSS classes across hundreds of individual <td> cells. Placed directly after <caption> and before <thead>, it contains one or more <col> elements with the 'span' attribute.

Explanation & In-Depth Details

1) Problem Solved by <colgroup>: If a table has 500 rows and you want to highlight the third column in light blue, repeating class="highlight" across 500 individual <td> elements inflates HTML payload size. <colgroup> solves this by styling the column once at the top of the table.

2) Placement in Document: The <colgroup> element must be placed before any <thead>, <tbody>, <tfoot>, or <tr> elements, and directly after <caption> if present.

3) The <col> Child Tag: Inside <colgroup>, individual columns are targeted using void <col> elements. A <col> can span multiple columns using the 'span' attribute (e.g. <col span="2">).

4) Supported CSS Properties on <col>: Due to browser rendering engine constraints, only four CSS properties can be applied to <col> and <colgroup>:
- 'background' (background-color, background-image)
- 'border' (when border-collapse is collapse)
- 'width' (column width)
- 'visibility' (visibility: collapse)

5) Combining Multiple Column Groups: You can define multiple <colgroup> tags to separate customer data columns from pricing and invoice calculation columns.

Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Colgroup Styling Showcase</title>
    <style>
        table { border-collapse: collapse; width: 100%; max-width: 650px; font-family: sans-serif; }
        th, td { border: 1px solid #cbd5e1; padding: 10px; text-align: left; }
        /* Styling entire columns via colgroup classes */
        .col-id { width: 60px; background-color: #f1f5f9; text-align: center; }
        .col-featured { background-color: #eff6ff; font-weight: 600; }
    </style>
</head>
<body>
    <h2>User Subscription Tiers</h2>
    <table>
        <!-- Column Group Definition -->
        <colgroup>
            <col class="col-id">
            <col style="width: 180px;">
            <col class="col-featured">
            <col style="width: 100px;">
        </colgroup>
        <thead>
            <tr>
                <th scope="col">ID</th>
                <th scope="col">Plan Name</th>
                <th scope="col">Storage Capacity</th>
                <th scope="col">Monthly Fee</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td>Starter</td>
                <td>15 GB Cloud Storage</td>
                <td>$0.00</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Professional</td>
                <td>500 GB Cloud Storage</td>
                <td>$12.00</td>
            </tr>
            <tr>
                <td>3</td>
                <td>Enterprise</td>
                <td>5 TB Cloud Storage</td>
                <td>$49.00</td>
            </tr>
        </tbody>
    </table>
</body>
</html>

Interview Question & Tips

Q1: Why doesn't 'color: red;' work when applied to a <col> or <colgroup> tag?
A1: According to CSS2.1 specifications, column elements do not exist in the DOM element tree as ancestors of cell elements. Browsers only permit four specific properties on columns: background, border, width, and visibility.

Q2: What is the function of the 'span' attribute on a <col> tag?
A2: The 'span' attribute defines how many consecutive columns the <col> styles apply to. For example, '<col span="3" style="background: #f8fafc;">' applies background color across the next three columns.

Q3: Can a table have multiple <colgroup> elements?
A3: Yes! Multiple <colgroup> elements can be used to demarcate major structural groups of columns (e.g. personal information columns vs billing columns).

Best Practices

Use <colgroup> to set column widths and alternating column background highlights cleanly without cluttering individual <td> cells.
Academic Standards & Verified Citations

This study reference for HTML Colgroup Tag: Structure, Attributes, and Examples is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation:

HTML & Web Development