HTML <colgroup> Tag

The <colgroup> tag serves as a container for <col> elements.

It is used to style one or more columns for all table rows.

The <colgroup> can have zero, one, or more <col> elements.



A <colgroup> with two <col> elements that specify the background colors.

Id First Name Last Name Country
ART-303 Vincent Van Gogh Netherlands
ART-877 Paul C├ęzanne France
  table.tb { width:100%; border-collapse: collapse; }
  .tb th, .tb td { padding:3px; border: 1px solid #777; }

<table class="tb">
    <col style="background-color:lightblue;">
    <col span="3" style="background-color:aliceblue;">
      <th>First Name</th>
      <th>Last Name</th>
      <td>Van Gogh</td>

col = column
colgroup = column group

Using <colgroup>

The <colgroup> tag is a container for <col> tags.

It can hold zero, one, or more <col> elements.

This tag must be located before other table elements like <thead>, <th>, and <td>.

Attributes for <colgroup>

This table lists the <colgroup> tag attributes.

Attribute Value Description
span number Number of columns a <colgroup> should span
id   identifier Defines a unique identifier for the colgroup.

For addional global attributes see our global attributes list.

Obsolete Attributes

Do not use the attributes listed below.  They are no longer valid on colgroup tag in HTML5.

Attribute Description Alternative
align Aligns the content in each column cell. CSS text-align
bgcolor Defines the background color for each column cell. CSS background-color
char Aligns content to a character, for example "," or ".". CSS text-align
charoff Shifts column data to the right relative to char attribute. CSS text-align
valign Sets the vertical alignment of content in each column cell. CSS vertical-align

Table Tags

The <colgroup> tag is part of a group of tags that are used to create HTML tables. This group is referred to as the Table tag group. Together, they allow you to create comprehensive HTML tables.

A list of table tags

Element Description
<table> Creates a table that contains elements listed below
<caption> Creates a caption above or under a table
<colgroup> Creates a container for col elements
<col> Creates a style for one or more columns in a table
<thead> Creates a table header that can style all header cells
<tbody> Creates a table body that can style all data cells
<tfoot> Creates table footer that can style all footer cells
<tr> Creates a table row that contains table cells
<th> Creates a table header cell
<td> Creates a table data cell

Browser support

Here is when <colgroup> support started for each browser:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

Last updated on Sep 30, 2023