Home | All Questions | alt.html FAQ > Deprecated Answers

How do I centre a table both horizontally and vertically on screen?

This solution is deprecated and should be avoided when creating standards-compliant or accessible websites.

This is possible, but only with some invalid markup (height is not a supported attribute in the HTML4.01 specifications, so its usefulness is seriously limited):

<table width="100%" height="100%">
 <tr>
  <td align="center">
   <table>
    <tr>
     <td>Your content goes here</td>
    </tr>
   </table>
  </td>
 </tr>
</table>
<table border="0" width="100%" height="100%"
    cellpadding="0" cellspacing="0">
<tr>
 <td width="100%" height="100%">
  Your content goes here
 </td>
</tr>
</table>

The above will put a 1 cell table 100% horizontal and vertically

It works with Internet Explorer, Netscape Navigator 4.x and Opera.

Netscape Navigator 6 and Mozilla only support W3C recommendations so those browsers will ignore the "height=100%" attribute and you'll lose vertical centering.

Recommended Resources

Discussion

Related Questions