How do we include attributes for table columns in HTML?

HTMLWeb DevelopmentFront End Technology

Use the <col> tag to include attributes for table columns. The HTML <col> tag allows authors to group together attribute specifications for table columns. It does not group columns together structurally -- that is the role of the <colgroup> element.

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
Specifies an alignment offset (either in pixels or percentage value) against the first character as specified with the char attribute, 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 <col> tag −

<!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>
raja
Published on 14-Mar-2018 10:43:26
Advertisements