1. Home
  2. Computing & Technology
  3. Web Design / HTML

Using HTML Tables - Attributes

Getting the Most Out of HTML Tables

By Jennifer Kyrnin, About.com

There are a lot of attributes available to tables to make them more interesting and change the look of your page.

HTML Table Tag Attributes

All these attributes belong in the <table> tag. Some of them have been deprecated. Where possible, I'll show the HTML for the attribute and then corresponding HTML that is valid in XHTML and not deprecated.

align

DEPRECATED This attribute is used to define where the table is located on the screen in relation to the text. It allows you to treat tables as images and put them in the same section as text on your page.

Deprecated example (note that this is still valid HTML 4.01):

<table align="right">
<tr><td>This table is right aligned</td></tr>
<tr><td>Text flows around it to the left</td></tr>
</table>

View

Valid example:

<table style="float:right;">
<tr><td>This table is floated to the right</td></tr>
<tr><td>Text flows around it to the left</td></tr>
</table>

View

background

NOT VALID
This is an attribute, that while supported in most browsers, is not valid XHTML. Use it to put a background image behind your table. Since this isn't valid, it's better to use the background style with cascading style sheets, and you get more control.

<table style="background: #fff url(/library/graphics/background.gif) repeat;">
<tr><td>This table has a background</td></tr>
</table>

View

bgcolor

NOT VALID
This is also a fairly widely supported attribute, but it is also not valid XHTML. You use it to change the background color of your table. But this is also covered by the background-color style in CSS:

<table style="background-color: #ccc;">
<tr><td>This table has a grey background</td></tr>
</table>

View

border

The border of a table sets the pixel width of the lines around and between cells in the table. Use the frame and rules attributes along with the border attribute to determine exactly what lines you want displayed.

<table border="1">
<tr><td>This table has a 1 pixel border around all cells</td></tr>
</table>

View

bordercolor

NOT VALID
This attribute is primarily supported by Internet Explorer, but it is not valid XHTML. For valid XHTML you should use the border-color style property. Be aware that this only affects the external border of the table, not the lines inside.

<table style="border-color: #f00; border-style:solid; border-width:1px;">
<tr><td>This table has a red border</td></tr>
</table>

View

bordercolorlight and bordercolordark

NOT VALID
These attributes only work with Internet Explorer, and in fact, even Microsoft does not recommend their use.

cellpadding

The amount of space between the cell borders and the contents. The default is 2, so set it to 0 if you want no cellpadding.

<table cellpadding="20">
<tr><td>This table has a cellpadding of 20.</td></tr>
<tr><td>Cells will be separated by 20 pixels.</td></tr>
</table>

View

cellspacing

The amount of space between the table cells and the cells. The default is 2, so set it to 0 if you want no cellspacing.

<table cellspacing="20">
<tr><td>This table has a cellspacing of 20.</td></tr>
<tr><td>Cells will be separated by 20 pixels.</td></tr>
</table>

View

class

The class attribute is used with styles to define a pre-determined set of attributes and apply it to all html elements of the same class.

Next page > Advanced Table Attributes > Page 1, 2

Previous Features

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. HTML and XHTML
  5. XHTML
  6. Tables
  7. HTML Table Attributes - Getting the Most Out of HTML Tables

©2008 About.com, a part of The New York Times Company.

All rights reserved.