The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

centering tables in XHTML

  • # June 2, 2008 at 8:12 pm

    did a Google serach on how to center a table in XHTML.

    the HTML code "align=center" does not validate in XHTML, it works but does not validate.

    found suggestion that you code "table {margin: 0 auto; text-align: center;}". tried this, and it
    validates in XHTML. found you did not need the "text-align: center" though.


    # June 2, 2008 at 9:38 pm

    I think the standard is to creat a "wrapper" div. some people call them wrapper and others call them page-wrapper. but the idea is to surround all your content like so

    <div id="wrapper">
    Your site content here.

    </div><!–END wrapper div–>

    then you can make a style sheet for your site


    margin:0 auto;

    # June 3, 2008 at 5:20 am

    This reply has been reported for inappropriate content.

    You would need to apply a width property or the margin method won’t work. Also, if its just the table as a whole you wish to have centred in the page…

    margin:0 auto;
    width:500px; /* or whatever width you want */

    I hope this table is being used for tabular data though – and not page layout ;)

    # June 3, 2008 at 10:49 am

    This reply has been reported for inappropriate content.

    I use a width and margin: 0 auto;

    the table is for tabular data not for layout. I want to rewrite the curling club website
    I maintain which currently makes extensive use
    of tables for layout.

    that is my summer project, conversion of the web site to an XHTML and CSS site only
    using tables for their proper purposes.


    # June 4, 2008 at 5:23 am

    This reply has been reported for inappropriate content.

    Good to hear – and good luck :D . One more thing to bear in mind is that you should use a strict doctype – Not only is this better generally and will help you use correct code/mark-up – but it will force IE6 into non-quirks mode and allow the margin:0 auto; to function correctly.

    # June 4, 2008 at 7:33 pm

    This reply has been reported for inappropriate content.

    I have self-taught myself HTML and CSS with help from some of the online tutorials and
    have tried to use XHTML for the web pages. I have also set them up as STRICT Doctypes.


Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed