HTML 4 for the World Wide Web, Fourth Edition: Visual QuickStart Guide - The Web Site
 
Chapter 9: Tables

Setting the Width

A browser will automatically determine the width of your table by calculating the width of the elements and text it contains. Somehow, it always seems to add a little extra. It’s particularly important to manually set the width of each cell and of the table as a whole in order to eliminate this extra space.

To set the width of a cell or table:

In the TD or TABLE tag, type WIDTH=n, where n is the desired width of the cell or of the entire table, in pixels.

Tips

  • You can also set the size of a cell or table as a percentage of the table or browser, respectively. The table will expand as the browser window is resized.
  • You can’t make the table too small for its contents; the browser will just ignore you.
  • The width of the table should be the sum of the width of the columns and their elements, the width of the border (see page 146), and the width of the cell spacing and cell padding (see page 155).
  • There is also a HEIGHT tag but it is non-standard, and not very well supported.
  • Generally, you only need to use the WIDTH tag with the first cell in each column. However, if you have cells that span columns or rows (see pages 152–153), it may be necessary to add the WIDTH attribute explicitly to every cell.
  • If you make the table wider than the browser’s window, the visitor may not be able to see the parts of the table that extend off to the right. I don’t recommend making tables any wider than 600 pixels.
Figure 9.9 Specify the width of each cell as well as of the entire table as a whole.
Figure 9.10 By setting the width of the entire table, the caption is divided into two lines—and looks much better.
Figure 9.11 Here I’ve revealed the border so you can see what’s going on.