This tag is used to specify the group of one or more columns in a table for formatting. It is useful for applying styles to entire columns, instead of repeating the styles for each column, and for each row. Use the <col> tag within the <colgroup> tag to define different properties to a column within a <colgroup>. Most of the attributes in HTML 4.01 <colgroup> are not supported in HTML5.
Syntax:
<colgroup> Column lists... </colgroup>
Attributes:
- align: It is used to align the text or content in the group of columns. The value of the aligned 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 colgroup tag. The values are in numeric form.
- valign: It specifies the vertical alignment of content in a colgroup. It’s values are the top, middle, bottom, baseline.
- width: It defines the width of a column group. It’s values are pixels, %, relative_length.
Example: The below example explains the HTML colgroup tag.
html
<!DOCTYPE html>
< html >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML colgroup tag</ h2 >
< table >
< colgroup >
< col span = "2" style = "background-color: green; color: white" />
< col style = "background-color: tomato" />
</ colgroup >
< tr >
< th >STUDENT</ th >
< th >COURSE</ th >
< th >AGE</ th >
</ tr >
< tr >
< td >Manas Chhabra</ td >
< td >BCA</ td >
< td >19</ td >
</ tr >
< tr >
< td >Anurag Gupta</ td >
< td >B.TECH</ td >
< td >23</ td >
</ tr >
</ table >
</ body >
</ html >
|
Output:

Supported Browsers:
- Google Chrome 1
- Edge 12
- Internet Explorer
- Firefox 1
- Opera
- Safari
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
21 Jul, 2022
Like Article
Save Article