×

Html <Col> Tag

You can write the col tag inside the table tag after the thead, tbody, foot, and tr tags. You can also apply it after the caption tag (in which the table's name is entered). 

The HTML col element is used to specify a column within a table and the common semantics for all common cells. This tag is found in colgroup element.
Only a few CSS properties are supported by col which can be used to style columns.

Syntax:

<col span = “ ”  style = “ ”>

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: powderblue">  
        <col span="2" style="background-color:   pink">  
    </colgroup>  
    <tr>  
        <th>Roll No.</th>  
        <th>Name</th>  
        <th>English</th>  
        <th>Social Science</th>  
    </tr>  
    <tr>  
        <td>14</td>  
        <td>Abhi</td>  
         <td>69</td>  
         <td>74</td>  
    </tr>  
    <tr>  
        <td>24</td>  
        <td>Jatin</td>  
         <td>85</td>  
         <td>91</td>  
    </tr>  
    <tr>  
        <td>32</td>  
        <td>Jenifier</td>  
         <td>65</td>  
         <td>98</td>  
    </tr>  
    <tr>  
        <td>41</td>  
        <td>Vivan</td>  
         <td>89</td>  
         <td>87</td>  
    </tr>  
</table>  
</body>  
</html>  

Output:

Html Col Tag

Attribute

The global attributes are present in this element.

Span

In the col element, this attribute specifies the amount of succeeding columns. It is always represented by the integer value and its default value is 1.

Align

This enumerated attribute describes how the content of each column cell will be aligned horizontally. This tag do these multiple following tasks:

  • Putting the content in the cell's left-most position.
  • Centering the cell's content.
  • Aligning the content so that it is to the cell's right.
  • To justify the text so that it fits within the cell by adding spaces to the text.

If the value is not set as the alignment in the align attribute of the colgroup element, then you have to determine the left as its value.

Bg-color

It is the color of the table's background. It is a 6-digit hexadecimal RGB code where # is a prefixed letter. You could also use any one color keyword instead of ‘#’.

You can also usee CSS background-color property to achieve a comparable

result.

Char

The character to be used to align the content in a column is selected by this property. When attempting to align numerical or monetary values, the period (.) is used as a value. This attribute is not taken into account if the alignment is not set to char.

Charoff

This attribute specifies how many characters of the column data should be offset from the alignment characters.

valign

This attribute specifies the vertical alignment of the text within each column cell. This attribute has the following possible values:

  • The baseline value will positioned the text as close to the bottom of the cell as physically possible by aligning it on the baseline of the characters rather than the bottom of the characters. All the same-sized characters produce the same result as the bottom.
  • The bottom value will positioned the text as close to the bottom of the column’s cell as possible.
  • The middle value will centered the text within the cell.
  • The top value will positioned the text as close to the top of the column’s cell as possible.

Width

This attribute specifies the default column width for the current column group. This attribute can also have the special form 0*, which indicates that each column in the group should have the minimum width that will be required to hold its contents.

Browser Compatibility

Chrome

Opera

Firefox

Safari

Problem With Col Tag

The col element has some advantages for making the styles to the columns in a table.

For styling columns in a table, the <col> element appears to be very useful, and it does have some advantages. However, there is a significant issue in the col tag is that the distinct cells of the table are not actually contained within the column because the table of HTML are defined by rows not by columns.

Another problem is that it colors the cell not the text of cell. This col element provide information about column. The properties that can be managed are:

  • Border
  • Background
  • Width
  • Visibility

Conclusion

The col tag specifies the properties of one or more columns. The col tag is frequently used in conjunction with the colgroup tag, which identifies a group with similar properties.


Related Topics

HTML <svg> tag

SVG is used to determine the vector-based graphics in XML format. What is SVG? We utilize SVG tag to specify visuals for the website. The attribute of SVG in a HTML document...

2 minutes read.

HTML City tag

HTML <City> tag HTML < cite > tag specifies a citation, a reference or title to a creative work, quoted content, books, websites, a research paper, a blog post, a painting,...

3 minutes read.

HTML <section> tag

The section element in HTML is used to define sections in a document. Syntax of Section Tag: <body> <h1>……….</h1> <section> <h2>……….</h2> <p> …………………………</p> </section> <section> <h2>………..</h2> <p>…………………………. <p> </section> </body> Examples of Section Tag Example 1: In this example, we use the HTML "section" element...

3 minutes read.

HTML Form Input Types

HTML Form Input Types An important element of the HTML form is < input type= "> in HTML. The type attribute of the input element can be of different types, which...

8 minutes read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

Html &lt;datalist >Tag

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out form...

4 minutes read.

Design a tribute page using HTML and CSS

A tribute page is a webpage based on a person who inspired us in our life. In this article, we will create a webpage of Mahatma Gandhi. We are going...

5 minutes read.

Html &lt;dd> Tag

In an HTML description list, an item's definition or description is indicated using the definition description ("dd" tag). A <dd> tag can contain paragraphs, line breaks, images, links, and lists. It...

4 minutes read.

HTML5 Attribute

HTML Attribute HTML attributes are special words that provide additional information about the HTML element or attributes.The element or tags have attributes, which define the element's behavior.It also adds attributes with a start...

3 minutes read.

What is a Container tag?

In HTML, there are different types of tags or say instructions which make the developer specify various elements in the document and make the browsers understand what to display. Tags in...

5 minutes read.

HTML Youtube

<object> element: It embed the object within the HTML documents and embed plug-ins such as Java applets, PDF readers, Flash Players etc in web pages. Example: <object width="100" height="100" data="bookmark.swf"></object> <embed> element: It defines an embedded...

1 minute read.

HTML <table> tag

The Table element If we want to show the data and information in a two-dimensional table with rows and columns, then we can achieve this by using the HTML element <table>. Syntax: <body> <table> <thead> <tr> <thcolspan="#">………….</th> </tr> </thead> <tbody> <tr> <td>……….</td> <td>……….</td> </tr> </tbody> </table> </body> Example: <!DOCTYPE...

9 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.

HTML <strong> tag

The strong element in HTML is used to display the real significant information in bold so that the user or reader will understand it easily. Syntax: <p> <strong>………… </strong> </p> Example Here, we will demonstrate how to...

2 minutes read.

How to add Google Translate Button on your Webpage?

Google translator is a multi-language translator used for translating the webpage. Google develops it. In today's digital age, it is essential because information is available worldwide in some specific language...

5 minutes read.

HTML <video> Tag

The Video tag in HTML is used to play video on a media player on the web page. We can also insert an audio by the video tag, but audio...

6 minutes read.

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

HTML Button Disabled

The HTML <button> element has many attributes, one of them is the disabled attribute. The button on which you apply the disabled attribute will not work, or we can say...

4 minutes read.

How to change font in HTML

To give style to the content of your website, you may change the font of the text and make your website look attractive to the user. There are several methods which...

4 minutes read.