Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Sizing a table

You can set the width and height of the table with the width and height attributes in the <table> tag. If you don’t enter a width, the browser determines the width of the table by the content of each column.

This example creates a table that is the full width of the Internet Explorer window:

<table width="100%">
<tr>
<td>Apples</td><td>Celery</td>
</tr>
<tr>
<td>Oranges</td><td>Carrots</td>
</tr>
</table>

In this example, the table width is given as a percentage of the total Internet Explorer window width. If you set the width to 75%, the table will always be 75% of the browser window no matter how wide or narrow the browser window is. You can also specify table widths in pixels.

You can also use these attributes for table cells so that the width is not determined by the width of the widest data in the cell. Again, you can give the width as a percentage or in pixels.

  • Note: You only need to enter the width for the cells in the first row of a table. Tables form with the cells in columns so subsequent cells take the width from the widths of the first row of cells.