Col HTML

HTML <col> Tag

In an HTML table, we can define common column properties for each column within <colgroup> element using the HTML <col> tag. Instead of applying individual style rules for each column cell, it allows to application of common style rules for each column cell. There is no need for an end tag for the HTML <col> tag, however, the XHTML <col> tag does require a closing </col> tag.

Syntax:

<col span=" " style=" ">

Example:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid brown;
}
</style>
</head>
<body>
 
<table width="400">
<caption>Students Details</caption>
  <colgroup>
  <col style="background-color:lightgray">
  <col span="2" style="background-color:lightyellow">
  </colgroup>
  <tr>
    <th>ID</th>
    <th>NAME</th>
    <th>SUBJECT</th>
  </tr>
  <tr>
    <td>101</td>
    <td>Happy Singh</td>
    <td>English</td>
  </tr>
  <tr>
    <td>201</td>
    <td>Smiley Das</td>
    <td>French</td>
  </tr>
   <tr>
    <td>301</td>
    <td>Joy Gupta</td>
    <td>Hindi</td>
  </tr>
</table>
</body>
</html>

Explanation:

In the above example, we are using the HTML <col> tag to define common column properties for each column within a <colgroup> element.

Tag-specific Attributes:

Attribute Value Uses HTML5
align left

right

center

justify

char

Used to define the content-alignment related to a <col> element. Not supported in HTML5.
char character Used to define the content alignment related to a <col> element to a character. Not supported in HTML5.
charoff number The character specified by the char attribute defines the number of characters with the content that will be aligned. Not supported in HTML5.
span number Used to define the number of columns which a <col> element should span.
valign top

middle

bottom

baseline

Used to define the vertical content alignment related to a <col> element. Not supported in HTML5.
width pixels

relative_length

Used to define the width of a <col> element. Not supported in HTML5.

Global Attributes:

All the Global attributes are supported by the HTML <col> tag.

Event Attributes:

All the Event attributes are supported by the HTML <col> tag.

Supporting Browsers:

Chrome, IE, Firefox, Opera, and Safari.

Please follow and like us:
Content Protection by DMCA.com