Center an html table

Quick tip.

Since css is the more ‘accepted’ way to apply formatting to html I discovered that the normal styles like align:center or text-align:center does not work anymore to center an html table horizontally.

Instead to be able to do it you need to add the following css definition:

table
{

margin-left:auto; margin-right:auto;

}

That will make it work in Firefox but not IE (9 as tested). To get IE to display it properly you need to enclose the whole table inside another tag – like a div:

<div class=”centerme”>

<table>

</table>

</div>

plus add css for the div:

div.centerme
{

margin-left:auto; margin-right:auto;text-align:center;

}

Not pretty but it works.

Leave a Reply

%d bloggers like this: