HTML <colgroup> Tag: The HTML<colgroup> tag defines a group of columns in a table for formatting. The HTML colgroup tag describes the column properties for each column. This tag can be used for applying styles to the entire column instead of repeating styles for each cell and each row.
HTML <colgroup> Tag
This HTML<colgroup> tag supports both the global and the event attributes. The <colgroup> tag must be a child of a <table> element, after any <caption> elements and before any <thead>, <tbody>, <tfoot>, and <tr> elements.
Syntax: <colgroup> <col span=” ” style=” “> </colgroup>
Attributes
- align: It is used to align the text or content in the group of the column. The value of the align property is left, right, center, justify, char.
- char: It is used to align the character in a column group and the value of these attributes is the character.
- charoff: It is used to sets the number of characters that will be aligned from the character specified by the char attribute. The value of these attributes is in numeric form.
- span: It is used to specify the number of columns that have a colgroup tag. The values are in numeric form.
- valign: It specifies the vertical-align of content in a colgroup. Its values are the top, middle, bottom, baseline.
- width: It defines the width of a column group. It’s values are pixels, %, relative_length.
Browser Support
This HTML colgroup tag was supported by a different type of browsers.
- Chrome
- Firefox
- InternetExplorer
- Opera
- Safari
Example:
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; } </style> </head> <body> <table> <colgroup> <col span="1" style="background-color:orange"> <col style="background-color:white"> <col style="background-color:green"> </colgroup> <tr> <th>ISBN</th> <th>Title</th> <th>Price</th> </tr> <tr> <td>2178965</td> <td>JAVA</td> <td>Rs.650</td> </tr> <tr> <td>5869651</td> <td>R programming</td> <td>Rs.490</td> </tr> </table> </body> </html>
Output:
Attributes that are supported by the <colgroup>tag
Attribute | Value | Description |
---|---|---|
align | left right center justify char |
Describes the alignment of the content in a column group |
char | Character | Describes the alignment of the content in a column group to a character |
charoff | number | Defines the number of characters the content will be aligned from the character specified by the char attribute |
span | number | Specifies the number of columns a column group should span |
valign | top middle bottom baseline |
Specifies the vertical alignment of the content in a column group |
width | % pixels relative_length |
Specifies the width of a column group |