×

Html <colgroup> Tag

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you require to the use a parent container.

Syntax

The colgroup tag is denoted by the characters <colgroup>…..</colgroup>. It can either contain one or more <col> tags, which can be used to represent

columns within the <colgroup> element. The <col> element can have a span

attribute which specifies how many columns to span.

<colgroup>Write Column Content Here</colgroup>

Example:

 <!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}
</style>
</head>
<body>


<h2>Colgroup</h2>
<p>Add the colgroup with a col element that spans over two columns to define a style for the two columns:</p>


<table style="width: 100%;">
<colgroup>
  <col span="2" style="background-color: #D6EEEE">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
</table>


</body>
</html>

Output:

Html Colgroup Tag

Attribute

The global attributes are present in this element.

Span

In the <col> element, this attribute specifies the amount of succeeding columns. It is always represented by the integer value and its default value is 1.

Align

This enumerated attribute describes how the content of each column cell will be aligned horizontally. This tag do these multiple following tasks:

  • Putting the content in the cell's left-most position.
  • Centering the cell's content.
  • Aligning the content so that it is to the cell's right.
  • To justify the text so that it fits within the cell by adding spaces to the text.

If the value is not set as the alignment in the align attribute of the <colgroup> element, then you have to determine the left as its value.

Bg-color

It is the color of the table's background. It is a 6-digit hexadecimal RGB code where # is a prefixed letter. You could also use any one color keyword instead of ‘#’.

You can also usee CSS background-color property to achieve a comparable

result.

Char

The character to be used to align the content in a column is selected by this property. When attempting to align numerical or monetary values, the period (.) is used as a value. This attribute is not taken into account if the alignment is not set to char.

Charoff

This attribute specifies how many characters of the column data should be offset from the alignment characters.

valign

This attribute specifies the vertical alignment of the text within each column cell. This attribute has the following possible values:

  • The baseline value will positioned the text as close to the bottom of the cell as physically possible by aligning it on the baseline of the characters rather than the bottom of the characters. All the same-sized characters produce the same result as the bottom.
  • The bottom value will positioned the text as close to the bottom of the column’s cell as possible.
  • The middle value will centered the text within the cell.
  • The top value will positioned the text as close to the top of the column’s cell as possible.

Width

This attribute specifies the default column width for the current column group. This attribute can also have the special form 0*, which indicates that each column in the group should have the minimum width that will be required to hold its contents.

Difference Between Col and Colgroup Tag

The semantic distinctions are the only thing that separates the COL tag and COLGROUP tag. The <COL> tag can undoubtedly span across more than two columns of the table, while COLGROUP tag groups the similar tasks according to meanings.

Browser Compatibility

Chrome

Opera

Firefox

Safari

Conclusion

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you require to the use a parent container. Colgroup tag is little bit different from the Col tag. Col specifies the column in the table while Colgroup groups the Column according to their meaning. 


Related Topics

HTML5 Attribute

HTML Attribute HTML attributes are special words that provide additional information about the HTML element or attributes.The element or tags have attributes, which define the element's behavior.It also adds attributes with a start...

3 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.

HTML Audio

HTML AUDIO: HTML5 provides a method to embed the audio file into a webpage by using HTML5. Before HTML5 audio files is used to play on the browser with the help of...

1 minute read.

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag. This <script> tag can be used for containing scripting statements. It can also point another external script file...

2 minutes read.

HTML <table> tag

The Table element If we want to show the data and information in a two-dimensional table with rows and columns, then we can achieve this by using the HTML element <table>. Syntax: <body> <table> <thead> <tr> <thcolspan="#">………….</th> </tr> </thead> <tbody> <tr> <td>……….</td> <td>……….</td> </tr> </tbody> </table> </body> Example: <!DOCTYPE...

9 minutes read.

HTML City tag

HTML <City> tag HTML < cite > tag specifies a citation, a reference or title to a creative work, quoted content, books, websites, a research paper, a blog post, a painting,...

3 minutes read.

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

HTML <span> tag

The span tag in HTML is used as an inline container element to mark up a specific or special chunk of a text or a section of a page. If you...

2 minutes read.

How to change font in HTML

To give style to the content of your website, you may change the font of the text and make your website look attractive to the user. There are several methods which...

4 minutes read.

How to Create a Portfolio Gallery using HTML and CSS?

First, before starting this, the user should know some of the basics of HTML and CSS to create a portfolio gallery. To add more functionality to the website, we can also...

7 minutes read.

HTML Paragraphs

In html, there are some elements which starts with new line and one of them is paragraph. Which is said to be a block of text. In html <p> tag...

4 minutes read.

HTML <strong> tag

The strong element in HTML is used to display the real significant information in bold so that the user or reader will understand it easily. Syntax: <p> <strong>………… </strong> </p> Example Here, we will demonstrate how to...

2 minutes read.

Responsive HTML5 and CSS3 Tutorial

Introduction to HTML5 Tutorial HTML5 is the latest and upgraded version of HTML. HTML is a hypertext markup language. Technically, it is not a programming language. It is a markup language. HTML...

17 minutes read.

HTML Video

HTML VIDEO: HTML5 has introduced the <video> tag to embed video into the webpage directly without using the plug-ins.   Syntax: <video attributes >     <source src="address" type="video/mp4">     Your browser does not support the video tag.   </video> <video width="320" height="240" controls>     <source src="mountain.mp4" type="video/mp4">     Your browser does not support the video tag.   </video> Output: ← Prev ...

1 minute read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

HTML Unordered List

In HTML, we have <ul> tag which defines the unordered list. And it is also known as bulleted list, because as we know it is not ordered list therefore it...

2 minutes read.

HTML Canvas

HTML Canvas: Using JavaScript, the < canvas > tag in HTML is used for drawing graphics on web page. It can be used to draw routes, boxes, text, gradient, and...

3 minutes read.

HTML Frames

Frames in Html is used to divide the browser into different sections where each section can load different Html documents. Collection of frame is known as Frameset. Creating frames:We use frameset...

2 minutes read.

Html <colgroup> Tag

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you...

4 minutes read.

Html &lt;dd> Tag

In an HTML description list, an item's definition or description is indicated using the definition description ("dd" tag). A <dd> tag can contain paragraphs, line breaks, images, links, and lists. It...

4 minutes read.