HTML <colgroup> Tag
Example
The <colgroup> and <col> tags set background colors for three columns in a table:
Browser Support
All major browsers support the <colgroup> tag.
Tag Definition and Usage
The <colgroup> tag is used to group columns in a table for formatting purposes.
By using the <colgroup> tag, you can apply styles to entire columns without having to repeat the styles for each cell or each row.
Note: The <colgroup> tag should be used within the <table> element, after any <caption> element, and before any <thead>, <tbody>, <tfoot>, <tr> elements.
Tip: To define different attributes for columns within a <colgroup>, use the <col> tag inside the <colgroup> tag.
Differences Between HTML 4.01 and HTML5
Most of the attributes from HTML 4.01 are no longer supported in HTML5.
Attributes
| Attribute | Value | Description |
|---|---|---|
| align | left <br>right <br>center <br>justify <br>char | Not supported in HTML5. Specifies the horizontal alignment of content in a column group. |
| char | character | Not supported in HTML5. Specifies the character to align content within a column group. |
| charoff | number | Not supported in HTML5. Specifies the offset of the first alignment character. |
| span | number | Specifies the number of columns a column group should span. |
| valign | top <br>middle <br>bottom <br>baseline | Not supported in HTML5. Defines the vertical alignment of content in a column group. |
| width | pixels<br> %<br> relative_length | Not supported in HTML5. Specifies the width of a column group. |
Global Attributes
The <colgroup> tag supports HTML's global attributes.
Event Attributes
The <colgroup> tag supports HTML's event attributes.