col

Defines properties for a single column or a span of columns within a colgroup. Use it to set column widths, apply background colors, or highlight specific columns in a table.

Description

The <col> element is a void element (self-closing) that must be placed inside a <colgroup>. It represents one or more columns in the table and allows you to apply styles to all cells in those columns without repeating attributes on each cell.

The most common uses are setting consistent column widths and applying background colors to entire columns for visual grouping or emphasis.

When to Use

  • Fixed column widths: set specific widths for columns that should not auto-size
  • Proportional sizing: define percentage-based widths for responsive tables
  • Column highlighting: apply background colors to draw attention to specific columns
  • Spanning multiple columns: use span to apply the same properties to several consecutive columns

Examples

This demo shows alternating column backgrounds applied through individual <col> elements, creating a striped column effect that helps users track data vertically.

The span Attribute

The span attribute applies the same properties to multiple consecutive columns from a single <col> element, avoiding repetition.

Attribute Value Description
span Positive integer (default: 1) Number of consecutive columns this element covers

Column Widths

Set fixed pixel widths, percentages, or auto to control column sizing.

Column Highlighting

Apply a subtle background to draw attention to a specific column, such as a recommended option in a comparison table.

Styling Limitations

The CSS specification restricts which properties work on <col> elements.

  • Supported: background, width, border (with collapsed borders), visibility: collapse
  • Not supported: padding, text-align, color, font properties

For unsupported properties, target cells directly with CSS selectors or use VB's data-numeric attribute for right-aligned numeric columns.

Accessibility

  • Presentational element: <col> is primarily for styling and does not convey semantic meaning to assistive technologies
  • Header associations: proper column semantics come from <th scope="col">, not from <col>
  • Color contrast: when using background colors, ensure text remains readable with sufficient contrast

Related

  • <colgroup> - parent container for col elements
  • <table> - the table container; see data-numeric for VB's built-in right-alignment
  • <th> - column headers that provide semantic meaning
  • <td> - data cells within columns