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=" ">  

Note: In HTML <col> tag does not require a closing tag but in XHTML it require a closing </col> tag.

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>

Comments

Leave a Reply

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