Centred DIV

Shows how to center a DIV in both browsers (Firefox and IE)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <title>example page</title>
    <style type="text/css" media="all">
        body {
            background-color: #ffffff;
            /* for IE: */
            text-align: center;
        #page {
            background: #eeeeee;
            /* for firefox, etc: */
            margin-left: auto;
            margin-right: auto;
            text-align: left;
            width: 70%;
    <div id="page">
            This content should be centered :-)
Snippet Details

See below

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments: