Placing a Table in the Center of a Page

Q

How do I center a table?

✍: FYIcenter

A

You place a table in the center of a page with the help of CSS as shown in this example:

In your HTML, use

<div class="center">
    <table>...</table>
</div>

In your CSS, use

div.center {
    text-align: center;
}
div.center table {
    margin-left: auto;
    margin-right: auto;
    text-align: left;
}

2007-03-03, 5212👍, 0💬