Centering a Table

You can draw attention to a table by centering it in the browser window.

To center a table with (X)HTML:

In the table tag, type align="center" (Figure 16.20).

Figure 16.20. The simplest way to center a table is to add the deprecated (but still well supported) center value to the align attribute.

To center a table with CSS:

1.
Make sure you’ve specified the width of the table (see page 232).
2.
Add margin-right: auto and margin-left: auto to the style rule for the table (Figure 16.21).
Figure 16.21. Setting the right and left margins to auto makes them equal—which is the essence of centering.

✓ Tips

  • You can also use ...

Get HTML, XHTML, & CSS, Sixth Edition: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.