What Is Colgroup Tag In HTML?
Có thể bạn quan tâm
The colgroup tag in HTML is used to format a group of columns in a table. It is used to set the properties of the columns altogether instead of manipulating individual ones.
The colgroup tag is used inside the table element and along with the col tag in HTML.
The illustration below shows how the colgroup tag works in HTML:
How does colgroup work in HTMLSyntax
The syntax of colgroup tag is as follows:
<colgroup> <col attribute = value> </colgroup>We begin by opening the tags using the <> symbol. In between, we write the keywordcolgroup. We then close the tags using the </> symbol. Once again, we will place the name of our tag in-between <> and after the / symbol. colgroup is used along with the col tag. The col tag has the following syntax:
<col attribute = value>We open the tags using the <> symbol. The keyword col and related attributes come within.
Attributes
Style attributes can be placed within the col tag. Some prominent ones are listed below:
| Attribute | Purpose |
|---|---|
| span | Used to indicate the number of consecutive columns to apply the specified properties on. By default, the value is 1. |
| background-color | Changes the background color of the columns. |
| width | Changes the width of the column. Value in pixels |
| height | Changes the height of the column. Value in pixels |
Example
The following code snippet shows how we can use the colgroup tag in HTML:
- HTML
span applies style attributes to the number of columns specified. In our case, we styled the first two columns together.
We can also style a single column. In that case, we need not specify a value for span. Instead, it chooses 1 by default. This is shown in the third column.
The width attribute adjusts the width of the column to the number of pixels specified. This is shown in the fourth column.
<tr>, <th> and <td> tags are used to place rows, headings and data respectively.
Relevant Answers
Explore Courses
Free Resources
Copyright ©2025 Educative, Inc. All rights reservedTừ khóa » Html Colgroup Background Color
-
HTML Colgroup Tag - W3Schools
-
HTML Table Colgroup - W3Schools
-
Colgroup Background Color Not Override Tr Background Color
-
HTML:
Tag - TechOnTheNet -
: The Table Column Group Element - MDN Web Docs -
HTML |
Bgcolor Attribute - GeeksforGeeks -
HTML Colgroup Tag - Web4College
-
HTML Col, Colgroup Tutorial With Examples - O7planning
-
HTML Colgroup Tag - Dofactory
-
Set Background For Column Group In HTML And CSS
-
HTML
Tag - W3docs -
HTML Table Colgroup - ForgeGeek
-
HTML - Colgroup Tag - Tutorialspoint
-
HTML Colgroup Tag | How To Specify Table Background Style?