The <colgroup> tag in HTML is used to group one or more <col> elements, allowing styles or attributes to be applied to entire table columns.
- Used to group multiple <col> elements in a table.
- Helps apply styles or attributes (like width) to entire columns.
- Placed inside the <table> tag before <thead>, <tbody>, and <tfoot>.
- Improves table structure and formatting efficiency.
<!DOCTYPE html>
<html>
<body>
<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>
Syntax:
<colgroup>
<col span="2" style="background-color: #f2f2f2;">
<col style="background-color: #e6f7ff;">
</colgroup>
Attributes
- span: span is used to specify the number of columns that have a colgroup tag. The values are in numeric form.