HTML <colgroup> Tag

Definition and Usage

<colgroup> The tag is used to specify the formatting of groups that contain one or more columns in a table.

If you need to apply styles to all columns<colgroup> The tag is very useful, so it is not necessary to repeatedly apply styles to each cell and each row.

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

Tip:If you need to apply a style to <colgroup> To define different properties for a column within <colgroup> Used in tags <col> Tag.

See also:

HTML Reference Manual:<col> Tag

HTML DOM Reference Manual:ColumnGroup Object

Example

Use the <colgroup> and <col> tags to set the background color of three columns:

<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>HTML Basics</td>
    <td>$53</td>
  </tr>
</table>

Try It Yourself

Attribute

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

Global Attributes

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

Event Attributes

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

Default CSS Settings

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

colgroup {
  display: table-column-group;
}

Try It Yourself

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support