colgroup

Groups one or more columns in a table for structural and styling purposes. Supports the span attribute for multi-column groups or individual col elements for per-column control.

Description

The <colgroup> element groups one or more columns in a <table> for structural or styling purposes. It must appear after the <caption> (if present) and before any <thead>, <tbody>, or <tfoot> elements.

A <colgroup> can either use the span attribute to cover multiple columns as a single group, or contain individual <col> elements for per-column control. These two modes are mutually exclusive: if <col> children are present, the span attribute is ignored.

When to Use

  • Column widths: set fixed or proportional widths for specific columns
  • Column highlighting: apply background colors to draw attention to specific columns
  • Semantic grouping: group related columns together (e.g., "H1 columns" vs "H2 columns" in a multi-header table)

When Not Needed

  • Simple tables: where all columns have equal treatment and auto-sized widths
  • Cell-level styling: when styles need to vary within a column, target cells directly with CSS

Examples

This demo shows a table with alternating column backgrounds applied via <col> elements inside a <colgroup>.

Using span

The span attribute applies properties to multiple consecutive columns without individual <col> elements.

Column Widths

Set proportional or fixed widths on <col> elements for consistent column sizing.

CSS Limitations

The CSS specification only allows a limited set of properties on <colgroup> and <col> elements.

Property Supported Notes
background Yes Background color and images
width Yes Column width (fixed or percentage)
border Partial Only with border-collapse: collapse (VB default)
visibility Yes Only the collapse value
padding No Apply to <th>/<td> instead
text-align No Use data-numeric or target cells with CSS

For properties not supported on column groups, target cells with CSS selectors or use VB's data-numeric attribute for right-aligned columns.

Attributes

Attribute Value Description
span Positive integer Number of columns the group spans. Cannot be used when <col> children are present.

Accessibility

  • Visual distinction: column background colors help users track data across rows, but ensure sufficient contrast
  • Not a replacement for headers: <colgroup> does not replace proper <th> headers with scope attributes
  • Column relationships: helps assistive technologies understand column groupings in complex tables

Related

  • <col> - individual column within a colgroup
  • <table> - parent container
  • <th> - column headers that provide semantic meaning
  • <td> - data cells within columns