Html – Center tag works fine, but align attribute doesn’t! What may be the issue

alignmentcsshtmltags

I am trying to align a complete page, to the center of a frame, and if I use center tag, it works fine. But, if I use

<body align=center>

or

<body style="align:center">

it doesn't align the page, but keep it left-aligned as default. Now, I am a newbie at HTML to be honest, so I don't have much idea, what may be causing this. Also, this happens only in non-IE browsers. IE shows the page center aligned, even without any tags.

Although, it is not of much significance, as I can always use center tag, but its nice to know why align attribute doesn't work. Kindly let me know, if anyone got any idea, as to what is the problem.

Edit:

Turns out, it is because of quirks mode. Thanks David and Town! đŸ˜€

Best Answer

To centre everything within the body, use text-align:

style="text-align: center;"

To centre an element within its container, give it a width and use margin, like this:

style="width: 600px; margin: 0 auto;"

EDIT: as other people have suggested, you should use a stylesheet to keep everything tidy. Put the following in your <head> (or reference a separate CSS file).

<style type="text/css">
   body { text-align: center; }
</style>