ExampleTwo <colgroup> elements. The first spans two columns and sets the background-color to red, the second sets the background-color to blue: | Browser Support |
1. Definition and Usage
The <colgroup> tag is used to group columns in a table for formatting.
The <colgroup> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.
The <colgroup> tag can only be used inside a <table> element.
2. Tips and Notes
Tip: Add the style attribute to the <colgroup> tag, and let CSS take care of backgrounds, width and borders.
Also have a look at the <col> tag.
3. Differences Between HTML 4.01 and HTML5
Most of the attributes in HTML 4.01 are not supported in HTML5.
4. Optional Attributes
DTD indicates in which HTML 4.01/XHTML 1.0 DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.
Attribute | Value | Description | DTD |
---|---|---|---|
align | left right center justify char | Aligns the content in a column group | STF |
char | character | Aligns the content in a column group to a character | STF |
charoff | number | Sets the number of characters the content will be aligned from the character specified by the char attribute | STF |
span | number | Specifies the number of columns a column group should span | STF |
valign | top middle bottom baseline | Vertical aligns the content in a column group | STF |
width | pixels % relative_length | Specifies the width of a column group | STF |
5. Standard Attributes
The <colgroup> tag supports the Standard Attributes in HTML.
6. Event Attributes
The <colgroup> tag also supports the Standard Event Attributes in HTML.