<colgroup> HTML table column group element

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

The <colgroup> HTML element defines a group of columns within a table.

Try it

<table>
  <caption>
    Superheros and sidekicks
  </caption>
  <colgroup>
    <col>
    <col span="2" class="batman">
    <col span="2" class="flash">
  </colgroup>
  <thead>
    <tr>
      <td></td>
      <th scope="col">Batman</th>
      <th scope="col">Robin</th>
      <th scope="col">The Flash</th>
      <th scope="col">Kid Flash</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Skill</th>
      <td>Smarts, strong</td>
      <td>Dex, acrobat</td>
      <td>Super speed</td>
      <td>Super speed</td>
    </tr>
  </tbody>
</table>
.batman {
  background-color: #d7d9f2;
}

.flash {
  background-color: #ffe8d4;
}

table {
  border-collapse: collapse;
  border: 2px solid rgb(140 140 140);
  font-family: sans-serif;
  font-size: 0.8rem;
  letter-spacing: 1px;
}

caption {
  caption-side: bottom;
  padding: 10px;
}

th,
td {
  border: 1px solid rgb(160 160 160);
  padding: 8px 6px;
}

td {
  text-align: center;
}

Attributes

This element includes the global attributes.

span

Specifies the number of consecutive columns the <colgroup> element spans. The value must be a positive integer greater than zero. If not present, its default value is 1.

Note: The span attribute is not permitted if there are one or more <col> elements within the <colgroup>.

Deprecated attributes

The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.

align

Specifies the horizontal alignment of each column group cell. The possible enumerated values are left, center, right, justify, and char. When supported, the char value aligns the textual content on the character defined in the char attribute and the offset defined by the charoff attribute. Note that the descendant <col> elements may override this value using their own align attribute. Use the text-align CSS property on the <td> and <th> elements instead, as this attribute is deprecated.

Note: Setting text-align on the <colgroup> element has no effect as <td> and <th> elements are not descendants of the <colgroup> element, and therefore they do not inherit from it.

If the table does not use a colspan attribute, use the td:nth-of-type(an+b) CSS selector per column, where a is the total number of the columns in the table and b is the ordinal position of the column in the table, e.g., td:nth-of-type(7n+2) { text-align: right; } to right-align the second column cells.

If the table does use a colspan attribute, the effect can be achieved by combining adequate CSS attribute selectors like [colspan=n], though this is not trivial.

bgcolor

Defines the background color of each column group cell. The value is an HTML color; either a 6-digit hexadecimal RGB code, prefixed by a #, or a color keyword. Other CSS <color> values are not supported. Use the background-color CSS property instead, as this attribute is deprecated.

char

Does nothing. It was originally intended to specify the alignment of the content to a character of each column group cell. Typical values for this include a period (.) when attempting to align numbers or monetary values. If align is not set to char, this attribute is ignored, though it will still be used as the default value for the align of the <col> elements which are members of this column group.

charoff

Does nothing. It was originally intended to specify the number of characters to offset the column group cell content from the alignment character specified by the char attribute.

valign

Specifies the vertical alignment of each column group cell. The possible enumerated values are baseline, bottom, middle, and top. Note that the descendant <col> elements may override this value using their own valign attribute. Use the vertical-align CSS property on the <td> and <th> elements instead, as this attribute is deprecated.

Note: Setting vertical-align on the <colgroup> element has no effect as <td> and <th> elements are not descendants of the <colgroup> element, and therefore they do not inherit from it.

If the table does not use a colspan attribute, use the td:nth-of-type() CSS selector per column, e.g., td:nth-of-type(2) { vertical-align: middle; } to center the second column cells vertically.

If the table does use a colspan attribute, the effect can be achieved by combining adequate CSS attribute selectors like [colspan=n], though this is not trivial.

width

Specifies a default width for each column in the current column group. In addition to the standard pixel and percentage values, this attribute can take the special form 0*, which means that the width of each column spanned should be the minimum width necessary to hold the column's contents. Relative widths such as 5* can also be used. Note that the descendant <col> elements may override this value using their own width attribute. Use the width CSS property instead, as this attribute is deprecated.

Usage notes

  • The <colgroup> should appear within a <table>, after any <caption> element (if used), but before any <thead>, <tbody>, <tfoot>, and <tr> elements.
  • Only a limited number of CSS properties affect <colgroup>:
    • background : The various background properties will set the background for cells within the column group. As the column group background color is painted on top of the table, but behind background colors applied to the columns (<col>), the row groups (<thead>, <tbody>, and <tfoot>), the rows (<tr>), and the individual cells (<th> and <td>), backgrounds applied to table column groups are only visible if every layer painted on top of them has a transparent background.
    • border: The various border properties apply, but only if the <table> has border-collapse: collapse set.
    • visibility: The value collapse for a column group results in all cells of the columns in that column group not being rendered, and cells spanning into other columns being clipped. The space these columns in the column group would have occupied is removed. However, the size of other columns is still calculated as though the cells in the collapsed column(s) in the column group are present. Other values for visibility have no effect.
    • width: The width property defines a minimum width for the columns within the column group, as if min-width were set.

Example

See <table> for a complete table example introducing common standards and best practices.

This example demonstrates a seven-column table divided into two <colgroup> elements that span multiple columns.

HTML

Two <colgroup> elements are used to structure a basic table by creating column groups. The number of columns in each column group is specified by the span attribute.

html
<table>
  <caption>
    Personal weekly activities
  </caption>
  <colgroup span="5" class="weekdays"></colgroup>
  <colgroup span="2" class="weekend"></colgroup>
  <thead>
    <tr>
      <th>Mon</th>
      <th>Tue</th>
      <th>Wed</th>
      <th>Thu</th>
      <th>Fri</th>
      <th>Sat</th>
      <th>Sun</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Clean room</td>
      <td>Football training</td>
      <td>Dance Course</td>
      <td>History Class</td>
      <td>Buy drinks</td>
      <td>Study hour</td>
      <td>Free time</td>
    </tr>
    <tr>
      <td>Yoga</td>
      <td>Chess Club</td>
      <td>Meet friends</td>
      <td>Gymnastics</td>
      <td>Birthday party</td>
      <td>Fishing trip</td>
      <td>Free time</td>
    </tr>
  </tbody>
</table>

CSS

Grouped columns can be used to visually highlight the structure using CSS:

css
table {
  border-collapse: collapse;
  border: 2px solid rgb(140 140 140);
}

caption {
  caption-side: bottom;
  padding: 10px;
}

th,
td {
  border: 1px solid rgb(160 160 160);
  padding: 8px 6px;
  text-align: center;
}

.weekdays {
  background-color: #d7d9f2;
}

.weekend {
  background-color: #ffe8d4;
}

Result

Technical summary

Content categories None.
Permitted content If the span attribute is present: none.
If the attribute is not present: zero or more <col> element
Tag omission The start tag may be omitted, if it has a <col> element as its first child and if it is not preceded by a <colgroup> whose end tag has been omitted.
The end tag may be omitted, if it is not followed by a space or a comment.
Permitted parents A <table> element. The <colgroup> must appear after any <caption> element, but before any <thead>, <tbody>, <tfoot>, and <tr> elements.
Implicit ARIA role No corresponding role
Permitted ARIA roles No role permitted
DOM interface HTMLTableColElement

Specifications

Specification
HTML
# the-colgroup-element

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
colgroup
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 4 (Release date: 2009-06-08)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 3.2 (Release date: 2010-04-03)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 3.2 (Release date: 2010-04-03)
footnote Full support
align
Deprecated
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote
footnote See bug 915
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote
footnote See bug 915
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 2 (Release date: 2008-07-11)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 2 (Release date: 2008-07-11)
footnote Full support
char
Deprecated
Chrome – No support
Chrome
footnote
footnote Since Chrome 1, the attribute can be set, but has no effect.
Edge – No support
Edge 12 – 18 (Release date: 2015-07-29)
footnote Removed in 79 and later
footnote Since Edge 79, the attribute can be set, but has no effect.
Firefox – No support
Firefox
footnote
footnote See bug 2212
Opera – No support
Opera
footnote
footnote Since Opera 15, the attribute can be set, but has no effect.
Safari – No support
Safari
footnote
footnote Since Safari 3, the attribute can be set, but has no effect.
Chrome Android – No support
Chrome Android
footnote
footnote Since Chrome Android 18, the attribute can be set, but has no effect.
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 2212
Opera Android – No support
Opera Android
footnote
footnote Since Opera Android 14, the attribute can be set, but has no effect.
Safari on iOS – No support
Safari on iOS
footnote
footnote Since Safari on iOS 2, the attribute can be set, but has no effect.
Samsung Internet – No support
Samsung Internet
footnote
footnote Since Samsung Internet 1.0, the attribute can be set, but has no effect.
WebView Android – No support
WebView Android
footnote
footnote Since WebView Android 4.4, the attribute can be set, but has no effect.
WebView on iOS – No support
WebView on iOS
footnote
footnote Since WebView on iOS 2, the attribute can be set, but has no effect.
charoff
Deprecated
Chrome – No support
Chrome
footnote
footnote Since Chrome 1, the attribute can be set, but has no effect.
Edge – No support
Edge 12 – 18 (Release date: 2015-07-29)
footnote Removed in 79 and later
footnote Since Edge 79, the attribute can be set, but has no effect.
Firefox – No support
Firefox
footnote
footnote See bug 2212
Opera – No support
Opera
footnote
footnote Since Opera 15, the attribute can be set, but has no effect.
Safari – No support
Safari
footnote
footnote Since Safari 3, the attribute can be set, but has no effect.
Chrome Android – No support
Chrome Android
footnote
footnote Since Chrome Android 18, the attribute can be set, but has no effect.
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 2212
Opera Android – No support
Opera Android
footnote
footnote Since Opera Android 14, the attribute can be set, but has no effect.
Safari on iOS – No support
Safari on iOS
footnote
footnote Since Safari on iOS 2, the attribute can be set, but has no effect.
Samsung Internet – No support
Samsung Internet
footnote
footnote Since Samsung Internet 1.0, the attribute can be set, but has no effect.
WebView Android – No support
WebView Android
footnote
footnote Since WebView Android 4.4, the attribute can be set, but has no effect.
WebView on iOS – No support
WebView on iOS
footnote
footnote Since WebView on iOS 2, the attribute can be set, but has no effect.
span
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 4 (Release date: 2009-06-08)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 3.2 (Release date: 2010-04-03)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 3.2 (Release date: 2010-04-03)
footnote Full support
valign
Deprecated
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote
footnote See bug 915
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote
footnote See bug 915
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 2 (Release date: 2008-07-11)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 2 (Release date: 2008-07-11)
footnote Full support
width
Deprecated
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 4 (Release date: 2009-06-08)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 3.2 (Release date: 2010-04-03)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 3.2 (Release date: 2010-04-03)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Deprecated. Not for use in new websites.
See implementation notes.

See also