How center that table?

Estela Gaspar
Jul 24, 2017 · 1 min read

Table align doesnt work anymore…

To center a table the old code below doesnt work anymore because the “align” attribute has been deprecated in favor of CSS — Yeahhhhh!

<table align="center">
...
</table>

However things are not a bit, bit more complex. So the solutions are:

Set the margins and give the table a class — Mozilla and Opera

CSStable.center {
margin-left:auto;
margin-right:auto;
}
---------------------
HTML
<table class="center">
...
</table>

For Internet Explorer 5.5 add to the CSS

body {text-align:center;}

To make the table fixed width use the following CSS

CSSdiv.container {
width:98%;
margin:1%;
}
table.tableA {
text-align:center;
margin-left:auto;
margin-right:auto;
width:468px;
}
tr,td {text-align:left;}---------------------<div class="container">
<table class="tableA">
...
</table>
</div>

Source: Scott Granneman, 2017

https://www.granneman.com/webdev/coding/css/centertables/

Written by

Email Marketing and Web Design at Europa Science — Cambridge

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade