docs.rodeo

MDN Web Docs mirror

: The Table Column Group element

{{HTMLSidebar}} 

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

{{EmbedInteractiveExample("pages/tabbed/colgroup.html","tabbed-taller")}} 

Attributes

This element includes the global attributes.

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.

Usage notes

Example

See {{HTMLElement("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.

<table>
  <caption>
    Personal weekly activities
  </caption>
  <colgroup span="5" class="weekdays"></colgroup>
  <colgroup span="2" class="weekend"></colgroup>
  <tr>
    <th>Mon</th>
    <th>Tue</th>
    <th>Wed</th>
    <th>Thu</th>
    <th>Fri</th>
    <th>Sat</th>
    <th>Sun</th>
  </tr>
  <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>
</table>

CSS

Grouped columns can be used to visually highlight the structure using 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;
}
table {
  font-family: sans-serif;
  font-size: 0.8rem;
  letter-spacing: 1px;
}

Result

{{EmbedLiveSample('Example', 650, 170)}} 

Technical summary

Content categories None.
Permitted content If the span attribute is present: none.
If the attribute is not present: zero or more `{{HTMLElement("col")}}`  element
Tag omission The start tag may be omitted, if it has a `{{HTMLElement("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 `{{HTMLElement("table")}}`  element. The <colgroup> must appear after any `{{HTMLElement("caption")}}`  element, but before any `{{HTMLElement("thead")}}` , `{{HTMLElement("tbody")}}` , `{{HTMLElement("tfoot")}}` , and `{{HTMLElement("tr")}}`  elements.
Implicit ARIA role No corresponding role
Permitted ARIA roles No role permitted
DOM interface `{{domxref("HTMLTableColElement")}}` 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN