Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Using col and colgroup to Apply Attributes to a Table Column

The col tag allows you to define attributes for one or more columns in a table. The colgroup tag allows you apply attributes to a group of columns.

Line1 Line2 Line3Line1
Line1 Line2 Line3Line1 Line2

Looking at the table above, you might decide that it would be more understandable if the data in the second column was aligned to the top of their table cells. You could accomplish this by adding the valign="top" attribute to each cell in the column as shown below.

<table width="100" border="1" cellpadding="4">
<tr><td>Line1 Line2 Line3</td><td valign="top">Line1</td></tr>
<tr><td>Line1 Line2 Line3</td><td valign="top">Line1 Line2</td></tr>
</table>

Line1 Line2 Line3Line1
Line1 Line2 Line3Line1 Line2

However, with a large table this might be tedious, and it adds unnecessary code. Instead you can use the col tag to define attributes for every cell in a column, as shown below.

<table width="100" border="1" cellpadding="4">
<col width="60">
<col valign="top">
<tr><td>Line1 Line2 Line3</td><td>Line1</td></tr>
<tr><td>Line1 Line2 Line3</td><td>Line1 Line2</td></tr>
</table>

Line1 Line2 Line3Line1
Line1 Line2 Line3Line1 Line2

Note: This works in Internet Explorer, however the Firefox browser does not recognize html attributes in the col tag. It does better with style attributes.

<table width="100" border="1" cellpadding="4">
<colgroup valign="top" >
<col />
<col />
<col />
</colgroup>
<tr><td>Line1 Line2 Line3</td><td>Line1</td><td>Line1 Line2</td></tr>
<tr><td>Line1 Line2 Line3</td><td>Line1 Line2</td><td>Line1</td></tr>
</table>

Line1 Line2 Line3Line1Line1 Line2
Line1 Line2 Line3Line1 Line2Line1

I have added another column to the table above. Using the colgroup tag I have applied the valign="top" attribute all three columns in one tag. For this to work in Internet Explorer, you still need the col tags within the colgroup tag. And again, the Firefox browser does not recognize html attributes in the colgroup tag.

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2024 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268