HTML col Tag

HTML <col> tag is employed to define shared column characteristics for every column inside the designated <colgroup> container in an HTML table.

The <col> tag is beneficial for implementing shared style rules across all column cells instead of applying them individually.

Syntax

Example

<col span=" "   style=" ">

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

Below are some details regarding the HTML <col> element:

Display Inline
Start tag/End tag Start tag(Empty tag)
Usage HTML tables

Example 1

Example

<!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:

Attribute:

Tag-specific Attribute

Attribute Value Description
align leftcenterrightjustifychar It specifies the horizontal alignment of each column cell.(Not supported in HTML5).
char character It 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).
charoff number It sets the number of characters to offset the column data from the alignment character specified by the char attribute. (Not supported in HTML5).
span number It specifies the number of the columns which a
valign topmiddlebottombaseline It specifies the vertical alignment of the columns.(Not supported in HTML5).
width %Pixelsrelative_length It specifies the width of the column.(Not supported in HTML5).
  • left
  • center
  • right
  • justify
  • char
  • middle
  • bottom
  • baseline
  • Pixels
  • relative_length
  • Global Attribute

HTML <col> tag accommodates all Global attributes available in HTML.

Event Attribute

HTML <col> tag accommodates all event attributes available in HTML.

Supporting Browsers

Element Chrome IE Firefox Opera Safari
<col> Yes Yes Yes Yes Yes

Input Required

This code uses input(). Please provide values below: