- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <colgroup> Tag
HTML <colgroup> tag is used to describe the collection of one or more columns in a table for formatting. Instead of duplicating the styles for each column and each row, it is excellent for applying styles to full columns.
To declare distinct characteristics for a column use the <col> tag within the <colgroup> tag. The <colgroup> tag must be a child of the <table> element, coming after any <caption> elements and before any <thead>, <tbody>, <tfoot>, and <tr> elements.
Syntax
<colgroup>...</colgroup>
Attribute
HTML colgroup tag supports Global and Event attributes of HTML. Some Specific attributes as well which are listed bellow.
Attribute | Value | Description |
---|---|---|
span | number | Specifies the number of consecutive columns the <col> element spans. |
align | left right center justify |
Specifies the alignment of text content(Deprecated). |
bgcolor | color | Specifies the background color of each column cell(Deprecated). |
char | character | Specifies the alignment of the content to a character of each column cell(Deprecated). |
charoff | number | Specifies the number of characters to offset the column cell content from the alignment character specified by the char attribute(Deprecated). |
valign | baseline bottom middle top |
Specifies the vertical alignment of each column cell(Deprecated). |
Examples of HTML colgroup Tag
Bellow examples will illustrate the usage of colgroup tag. Where, when and how to use colgroup tag to offer information about columns.
Using colgroup tag with Table
Following is an example where we are going to use the <colgroup> tag in the table.
<!DOCTYPE html> <html> <body> <table border="1"> <colgroup> <col style="background-color:#ABEBC6"> <col style="background-color:#BB8FCE"> </colgroup> <tr> <th>Roll.No</th> <th>Name</th> </tr> <tr> <td>1</td> <td>Maya</td> </tr> <tr> <td>2</td> <td>Surya</td> </tr> <tr> <td>3</td> <td>Ram</td> </tr> </table> </body> </html>
Specifying Consecutive Columns
Consider another scenario where we are going to use the span attribute with the <colgroup> tag.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #DE3163; } </style> <body> <table> <colgroup> <col span="2" style="background-color:#F9E79F"> </colgroup> <tr> <th>Item</th> <th>Price</th> </tr> <tr> <td>5-Star</td> <td>$10</td> </tr> <tr> <td>Dairy-Milk</td> <td>$50</td> </tr> <tr> <td>Kitkat</td> <td>$20</td> </tr> </table> </body> </html>
Styling Colgroup Element
In the following example, we are going to apply CSS to the middle of the table by passing an empty <col> without applying the style for the column before.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #85C1E9; border-collapse: collapse; } </style> <body> <table style="width: 50%;"> <colgroup> <col span="1"> <col span="1" style="background-color: #ABEBC6 "> </colgroup> <tr> <th>MON</th> <th>TUE</th> <th>WED</th> <th>THU</th> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> <tr> <td>9</td> <td>10</td> <td>11</td> <td>12</td> </tr> </table> </body> </html>
Hiding Column
Let’s look at another example where we are going to hide the column using the visibility:collapse property.
<!DOCTYPE html> <html> <style> table, th, td { border: 1.5px solid #DE3163; border-collapse: collapse; } </style> <body> <table style="width: 100%;"> <colgroup> <col span="2"> <col span="3" style="visibility: collapse"> </colgroup> <tr> <th>ID</th> <th>Employee</th> <th>Department</th> <th>Age</th> </tr> <tr> <td>112</td> <td>Rahul</td> <td>IT</td> <td>22</td> </tr> <tr> <td>113</td> <td>Ram</td> <td>Associate</td> <td>24</td> </tr> <tr> <td>114</td> <td>Maya</td> <td>HR</td> <td>30</td> </tr> <tr> <td>115</td> <td>Rahul</td> <td>BPO</td> <td>23</td> </tr> </table> </body> </html>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
colgroup | Yes | Yes | Yes | Yes | Yes |
To Continue Learning Please Login
Login with Google