HTML <col> tag


HTML <col> tag is used to specify common column properties for each column within <colgroup> element in an HTML table.

The <col> tag is useful when it requires to apply common style rules for each column cell rather than applying individually.

Syntax:

<col span=" "   style=" ">  

Following are some specifications about the HTML <col> tag

DisplayInline
Start tag/End tagStart tag(Empty tag)
UsageHTML tables

Example 1:

<!DOCTYPE html>  
<html>  
<head>  
    <title>Col tag</title>  
</head>  
<body>  
<h2>Example of Col Tag</h2>  
<table border="1">  
    <colgroup>  
        <col  span="2" style="background-color: #7fffd4">  
        <col span="2" style="background-color:   #98f5ff">  
    </colgroup>  
    <tr>  
        <th>Roll No.</th>  
        <th>Name</th>  
        <th>Maths</th>  
        <th>Science</th>  
    </tr>  
    <tr>  
        <td>1</td>  
        <td>Avinash</td>  
         <td>68</td>  
         <td>54</td>  
    </tr>  
    <tr>  
        <td>2</td>  
        <td>Neha</td>  
         <td>65</td>  
         <td>61</td>  
    </tr>  
    <tr>  
        <td>3</td>  
        <td>Jenny</td>  
         <td>55</td>  
         <td>78</td>  
    </tr>  
    <tr>  
        <td>4</td>  
        <td>Vivek</td>  
         <td>75</td>  
         <td>52</td>  
    </tr>  
</table>  
</body>  
</html>  

Output:

HTML col tag

Attribute:

Tag-specific Attributeelement should contain. The default value of span attribute is 1.

AttributeValueDescription
alignleftcenterrightjustifycharIt specifies the horizontal alignment of each column cell.
(Not supported in HTML5).
charcharacterIt specifies the alignment of content based on Characters in a column. It will be ignored if align is not set to char. (Not supported in HTML5).
charoffnumberIt sets the number of characters to offset the column data from the alignment character specified by the char attribute. (Not supported in HTML5).
spannumberIt specifies the number of the columns which a
valigntopmiddlebottombaselineIt specifies the vertical alignment of the columns.
(Not supported in HTML5).
width%Pixelsrelative_lengthIt specifies the width of the column.
(Not supported in HTML5).

Global Attribute

HTML <col> tag supports all Global attributes in HTML.

Event Attribute

HTML <col> tag supports all event attributes in HTML.

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<col>YesYesYesYesYes

Leave a Reply

Your email address will not be published. Required fields are marked *