The more common method is the following (align="center" isn't valid markup); Inside BODY tag <div id="wrap"> *** CONTENT </div> Code (markup): And the CSS; #wrap { margin:0 auto; } Code (markup): The 0 means there is no margin at the top or bottom of your wrap div... Auto sets the left/right margins to automatic which centers the div in the middle of the screen. Finally, remember to set a width in the CSS of '#wrap' and everything will be fine. If you want it to work with IE5/6 add the following CSS; body { text-align:center; } #wrap { text-align:left; } Code (markup):
to center a page in the body tag simply use <body style="text-align:center"> or simply do it without inlined styles. wrap the whole page in a table or div and center that with the style="text-align:center". simple.
It doesn't work in ANY browsers except IE5.5 and older. Unless you don't have a doctype, in which case it will also work in IE6 and 7 in Quirks Mode.
it works in the latest version of firefox too, and the latest IE. <body style="text-align: center;"> is the standard. Styles in HTML is the most current standard.
The best way to do it using CSS and have no problems with different browsers is: Considering a that your width is 850px do: position:absolute; left:50%; top:50%; margin-left:-425px; margin left need to be width/2. Always negative.
Test. Explanation on how to do it properly and why IE is the only buggy browser on the planet who does it incorrectly (not counting ancient versions of modern browsers such as Opera 6 or Nutscrape 4). On IE5.5 and below, text-align: center is the only way to center a block because it doesn't know any better. IE6 and 7, so long as they have a proper Doctype, can use automargins but for backwards compatibility they left the bugs from IE5.5 and older in. I stand corrected that IE doesn't need to be in Quirks Mode to center blocks with text-align, rather it's that in Quirks Mode it cannot use the modern auto-margin method, while with a Doctype it can the same as Modern Browsers. IE 8 acts like a modern browser, and does not obey text-align on a block element. Text-align centers inline content. willrs example can work most of the time but only if you already know the width of your box. It also takes the block out of the document flow (which might not matter if it's container the entire page).