HTML Table variability

In past columns, we have investigated the basic structure of HTML tables and their many properties; showing you how to create basic tables and insert data, images and additional code into them.

Many Web sites may require a deeper level of table imple­mentation. This month we investigate an advanced table technique, which enables you to set out your entire HTML page so it is sized equally on various screen size resolutions.

Screen sizes

The two most commonly implemented screen size resolutions are 800x600pixels (WxH) or 1024x768. Often you will encounter a Web site that requires you to scroll to the right to view the entire page content; this usually occurs if the developer has designed the site for the larger of these two resolutions, without considering how people using the smaller setting of 800x600 will see it.

You can find out which screen resolution your computer is set to, or change it for testing purposes. Right-click the desktop: a drop-down menu will appear from which you select Properties. Click the Settings tab and you'll see a sliding bar, which you can move to the desired resolution. Click Apply, then click OK to confirm.

Table variability

Table variability is the act of defining your table width so the Web page resizes itself according to the current screen resolution or browser window size used by the viewer.

Below is the code for a table with a width of 760pixels. This is how many people code their Web sites - setting a definitive width, which will NOT change if the screen settings change. If using this approach, for optimum display you should set the width to suit the smaller screen resolution and centre your table. The problem is that it will fill a comparatively small amount of a screen at 1024x768.

<table width="760" border="1" align="center">
    <td bgcolor="orange">One</td>
    <td bgcolor="pink">Two</td>
    <td bgcolor="yellow">Three</td>
  </tr> </table>

This example sets out a basic one-row, three-column table with a width of 760pixels, centred on the screen. It fits quite snugly when the screen resolution is 800x600, but there is a lot of empty space on either side of the table at 1024x768.

Setting table widths

To allow for table variability, the first step is to set the table width to 100 per cent. If you were to insert "width=100%" in place of "width=760" in the above example, you would see that no matter what the screen resolution is, the table fills the screen.

TIP: You can do a simple test to check if your resizing works by clicking the Restore [Window] button (the middle button on the top right of your browser window, between the Minimize and Close buttons). Grab the corners of the window with your mouse and drag in and out to see the effect. Click it again to return to maximum resolution.

TD widths

Now that you know how to make your table adapt to various resolutions, you should look at specific cells (TDs). Using the above example, let's assume we want both the orange and yellow TDs to be 10 per cent of the page, regardless of size.

This would leave the middle cell to fill what is left over, which is 80 per cent of the browser window in this case. You can define this TD as well if you wish, but there is no need if the other cells are already set.

<table width="100%" border="1" align="center">
    <td bgcolor="orange" width="10%">One</td>
    <td bgcolor="pink">Two</td>
    <td bgcolor="yellow" width="10%">Three</td>

If you had decided to give your table a fixed width of 760, but still inserted the percentage widths in the TDs, then they would fill 10 per cent of the 760pixel-wide table. Essentially, you need to set the table width, so the cells can display that percentage.

Join the newsletter!


Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Heidi Woof

PC World
Show Comments

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Tom Pope

Dynabook Portégé X30L-G

Ultimately this laptop has achieved everything I would hope for in a laptop for work, while fitting that into a form factor and weight that is remarkable.

Tom Sellers


This smart laptop was enjoyable to use and great to work on – creating content was super simple.

Lolita Wang


It really doesn’t get more “gaming laptop” than this.

Jack Jeffries


As the Maserati or BMW of laptops, it would fit perfectly in the hands of a professional needing firepower under the hood, sophistication and class on the surface, and gaming prowess (sports mode if you will) in between.

Taylor Carr


The MSI PS63 is an amazing laptop and I would definitely consider buying one in the future.

Christopher Low

Brother RJ-4230B

This small mobile printer is exactly what I need for invoicing and other jobs such as sending fellow tradesman details or step-by-step instructions that I can easily print off from my phone or the Web.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?