How to include groups of table columns in HTML?


Use the <colgroup> tag to include groups of table columns.The HTML <colgroup> tag is used for specifying properties for a group of columns within a table. If you need to apply different properties to a column within a colgroup, you can use the HTML col tag within the colgroup tag.

The following are the attributes −

Attribute
Value
Description
Align
right
left
center
justify
char
Defines horizontal alignment, not supported in Html5.
Char
character
Defines a character to use to align text on (use with align ="char"), not supported in Html5.
Charoff
pixel
Defines the number of columns the <col> should span, not supported in Html5
Span
number
Defines the number of columns the <col> should span, not supported in Html5.
Valign
bottom
middle
top
baseline
Defines vertical alignment, not supported in Html5.
Width
pixels or %
Specifies a default width for each column spanned by the current col element, not supported in Html5 .

Example

You can try to run the following code to implement <colgroup> tag in HTML −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML col Tag</title>
   </head>
   <body>
      <p>This example shows a colgroup that has three columns of different widths:</p>
      <table border = "1">
         <colgroup span = "4">
            <col width = "40"></col>
            <col width = "70"></col>
            <col width = "100"></col>
            <col width = "130"></col>
            <col width = "160"></col>
            </colgroup>
         <tr>
            <td>One</td>
            <td>Two</td>
            <td>Three</td>
            <td>Four</td>
            <td>Five</td>
         </tr>
      </table>
   </body>
</html>

Updated on: 30-May-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements