**`<colgroup>`** must appear right after `<caption>` (if present) and before `<thead>`/`<tr>` in a table, and it exists purely to hold `<col>` children (or, less commonly, a `span` attribute directly on the `<colgroup>` itself to cover multiple columns with shared styling in one declaration, without individual `<col>` children).
1Understanding <colgroup>
`<colgroup>` must appear right after <caption> (if present) and before <thead>/<tr> in a table, and it exists purely to hold <col> children (or, less commonly, a span attribute directly on the <colgroup> itself to cover multiple columns with shared styling in one declaration, without individual <col> children).
If every column in the group shares identical styling, you can skip individual <col> children entirely and just put a span attribute directly on <colgroup> — e.g. <colgroup span="4" style="...">.
<table>
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<tr><td>Label</td><td>Longer value column</td></tr>
</table>2Practical Example
Here is a real-world application of <colgroup> showing how it is used in production HTML.
<!-- Single colgroup with span, no individual col children -->
<table>
<colgroup span="3" style="background-color: #f9f9f9;"></colgroup>
<tr><td>A</td><td>B</td><td>C</td></tr>
</table>3Best Practices
Follow these guidelines when working with <colgroup>:
1. Place <colgroup> immediately after <caption> and before <thead>/<tr>
2. Use it to define shared column widths/backgrounds once, instead of repeating styles per cell
3. Use the span attribute directly on <colgroup> when all its columns share identical styling
Tip: If every column in the group shares identical styling, you can skip individual <col> children entirely and just put a span attribute directly on <colgroup> — e.g. <colgroup span="4" style="...">.
<table>
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<tr><td>Label</td><td>Longer value column</td></tr>
</table>