Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

<colgroup>, <col>

Describes table columns so you can give them a width or background.

Syntax

<colgroup><col span="2"><col class="total"></colgroup>

Attributes

ParameterTypeDescription
spannumberHow many columns a `<col>` covers.

Examples

Highlighting the last column:

<style>
  .total { background: lightyellow; }
  table { border-collapse: collapse; }
  td, th { padding: 4px 10px; }
</style>
 
<table>
  <colgroup><col span="2"><col class="total"></colgroup>
  <tr><th>Item</th><th>Qty</th><th>Sum</th></tr>
  <tr><td>Latte</td><td>2</td><td>$9.00</td></tr>
  <tr><td>Tea</td><td>1</td><td>$2.50</td></tr>
</table>

Notes

<colgroup> comes right after <caption>, before the rows. Only a few properties work on <col>: background, width, border and visibility — you cannot set text colour or padding this way.

See also

  • <table> — A table made of rows (`<tr>`) and cells.
  • <td>, <th> — Table cells: `<td>` holds data, `<th>` is a header cell.

Related recipes

In the tutorial

  • Tables — Tables in HTML — rows and cells, column headers, thead, tbody, tfoot and caption, merging cells.

Thanks for reading!

Donate to the site — we work hard for you.