<col>
One or more columns in a `<colgroup>`, for styling a whole column at once.
- Display
- table-column
- Closing tag
- None, void element
- Permitted content
- None, an empty element
Example
#<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #8886; padding: 4px 10px; }
.recommended { background: #f9731633; }
</style>
<table>
<colgroup>
<col>
<col>
<col class="recommended">
</colgroup>
<tr><th scope="col">Feature</th><th scope="col">Start</th><th scope="col">Pro</th></tr>
<tr><th scope="row">Courses</th><td>3</td><td>all</td></tr>
<tr><th scope="row">Mentor</th><td>no</td><td>yes</td></tr>
</table>Definition and usage
#The <col> element represents one column of a table, or, with the span attribute, several adjacent columns. It is an empty element and sits inside <colgroup>.
It contains no content, because you still write the cells in <tr> rows. <col> exists only so you can give a whole column a class and style it at once, for example with a background or a width.
The same limits apply as for <colgroup>: a column accepts only background, border (with collapsed borders), width, and visibility: collapse.
Syntax
#<colgroup>
<col span="2">
<col class="โฆ">
</colgroup>Attributes
#positive number (default 1)
The number of adjacent columns this element covers. Instead of writing three identical<col>elements, you write one withspan="3".
The element also supports all global attributes, such as class, id, style and hidden.
Attributes in practice
#span
positive number (default 1)The number of adjacent columns this element covers. Instead of writing three identical <col> elements, you write one with span="3".
<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #8886; padding: 4px 10px; }
.scores { background: #10b98126; }
</style>
<table>
<colgroup>
<col>
<col span="2" class="scores">
</colgroup>
<tr><th scope="col">Student</th><th scope="col">HTML</th><th scope="col">CSS</th></tr>
<tr><th scope="row">Ola</th><td>9</td><td>8</td></tr>
</table>Default CSS
#Most browsers display this element with these default styles:
col {
display: table-column;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- A width set on
<col>, for examplewidth: 40%, together withtable-layout: fixedon the table gives a stable column layout that doesnโt depend on the content. - A border set on
<col>appears only withborder-collapse: collapse.
Related entries
#Spotted a mistake or missing an example? Write to us.