×

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 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 <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 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.

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 Hide Element

The HTML hide element is used to hide the element. We place the hidden attribute inside those elements which we want to hide. The hidden attribute is a Boolean attribute. The...

3 minutes read.

HTML Layouts

HTML Layouts HTML templates provide a way for well-managed, well-structured responsive web pages to be organized. We could say that the HTML layout specifies how web pages can be set up....

4 minutes read.

HTML Links

It consist of anchor element which is used to create a link between a source anchor and destination anchor. The anchor tag can be embedded between text, image, video or...

2 minutes read.

How to insert spaces/tabs in text using HTML/CSS

What is HTML? HTML or HyperText Markup Language is used to design web pages. It was released in 1993. The file extension name for HTML file is “.html”. An HTML file...

4 minutes read.

Div Tag in HTML

In HTML, ‘div’ is a tag that specifies division or section in HTML document. But before going in detail of it, let’s first understand about tags in HTML. The tag...

8 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.

HTML Search Box

The HTML search box is also known as the search bar. It is an input text field that is used to search the content. If the users want to explore...

7 minutes read.

How to create a link with no underline in HTML

In HTML, an anchor tag (<a>) is a Styled Container tag, which means when a hyperlink is created using this, browsers, by default, display the link by applying some styles...

5 minutes read.

HTML Tutorial

Introduction This HTML tutorial helps beginners and professionals to learn HTML easily. HTML is a widely used web technology for website development. It stands for Hyper Text Markup Language. It is mainly used to...

7 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 Video

HTML VIDEO: HTML5 has introduced the <video> tag to embed video into the webpage directly without using the plug-ins.   Syntax: <video attributes >     <source src="address" type="video/mp4">     Your browser does not support the video tag.   </video> <video width="320" height="240" controls>     <source src="mountain.mp4" type="video/mp4">     Your browser does not support the video tag.   </video> Output: ← Prev ...

1 minute 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.

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.

HTML 5 Tutorial

What is HTML5? HTML5 is a programming language which stands for the acronym Hyper Text Markup Language 5. It is program that enables the appearance of web pages to be changed, as well as changes...

5 minutes read.

HTML Text Format

Introduction HTML may format text in two different ways. The HTML tags define a text property to make it appear one way or another. A text element may also be formatted...

7 minutes read.

HTML Canvas

HTML Canvas: Using JavaScript, the < canvas > tag in HTML is used for drawing graphics on web page. It can be used to draw routes, boxes, text, gradient, and...

3 minutes read.