center table in HTML

alignment, html, html-table

Solution

Give width to table, and set margin auto horizontally.

table {
  width:500px;
  margin: 10px auto;
}

Problem

How can I center the `table` within a `div` using html? I have placed my content within a `div` tag and set the `text-align` attribute to `center` like the following. ``` text-align: center; ``` This has not worked. Below is my html. ``` <html> <body> <div style="text-align:center"> <p> text test </p> <table border="1"> <tr> <td>100</td> <td>200</td> <td>300</td> </tr> <tr> <td>400</td> <td>500</td> <td>600</td> </tr> </table> </div> </body> </html> ```

Original source