Related Articles

Related Articles

HTML | <colgroup> Tag
  • Difficulty Level : Basic
  • Last Updated : 30 Jul, 2019

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>.

Note: 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 column. The value of align property are left, right, center, justify, char.
  • char: It is used to align the character in a column group and the value of this attributes are 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 this attributes are 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 align of content in a colgroup. It’s values are top, middle, bottom, baseline.
  • width: It defines the width of a column group. It’s values are pixels, %, relative_length.

Note: Most of the attributes are not supported by <colgroup> tag in HTML5.



Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <style>
            table, th, td {
                border: 1px solid black;
                color:white;
            }
            h2, h3 {
                color:green;
            }
        </style>
    </head>
      
    <body>
        <center>
            <h2>GeeksForGeeks</h2>
            <h3><colgroup> tag</h3>
            <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>Mukul Gupta</td>
                    <td>B tect</td>
                    <td>20</td>
                </tr>
            </table>
            </body>
        </center>
</html>                    

chevron_right


Output:

Supported Browsers: The <colgroup> tag supported browsers listed below.

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :