BEST SITE FOR WEB DEVELOPERS
HTML5. W3Schools in English. The complete tag guide

Ua

HTML <colgroup> Tag


Example

Set the background color of the three columns with the <colgroup> and <col> tags:

<table>
  <colgroup>
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
</table>
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The <colgroup> tag specifies a group of one or more columns in a table for formatting.

The <colgroup> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.

Note: The <colgroup> tag must be a child of a <table> element, after any <caption> elements and before any <thead>, <tbody>, <tfoot>, and <tr> elements.

Tip: To define different properties to a column within a <colgroup>, use the <col> tag within the <colgroup> tag.


Browser Support

Element
<colgroup> Yes Yes Yes Yes Yes

Attributes

Attribute Value Description
span number Specifies the number of columns a column group should span

Global Attributes

The <colgroup> tag also supports the Global Attributes in HTML.


Event Attributes

The <colgroup> tag also supports the Event Attributes in HTML.


More Examples

Example

Align text in table columns (with CSS):

<table style="width:100%">
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
   <td>3476896</td>
    <td>My first HTML</td>
    <td style="text-align:right">$53</td>
  </tr>
  <tr>
    <td>2489604</td>
    <td>My first CSS</td>
    <td style="text-align:right">$47</td>
  </tr>
</table>
Try it Yourself »

Example

Vertical-align text in table columns (with CSS):

<table style="height:200px">
  <tr>
    <th>Month</th>
    <th style="vertical-align:bottom">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td style="vertical-align:bottom">$100</td>
  </tr>
</table>
Try it Yourself »

Example

Specify width of a table column (with CSS):

<table>
  <tr>
    <th style="width:200px">Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>
Try it Yourself »

Related Pages

HTML DOM reference: ColumnGroup Object


Default CSS Settings

Most browsers will display the <colgroup> element with the following default values:

Example

colgroup {
  display: table-column-group;
}
Try it Yourself »