How To Center Align HTML Table

In this tutorial we will see How To Center Align HTML Table. We have used simple margin-left and margin-right CSS properties to center align HTML Table.

HTML Code

Write HTML Code of HTML Table, simple example is given below.

<table class="center">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Phone</th>
  </tr>
  <tr>
    <td>Tom</td>
    <td>Harry</td>
    <td>87932</td>
  </tr>
  <tr>
    <td>Sara</td>
    <td>David</td>
    <td>69123</td>
  </tr>
</table>

CSS Code

CSS Code is given below. Simple margin-left and margin-right properties of CSS are used to center align the HTML Table. You can also add text-align:center; to center align the text of table as well.

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

Demo

Video Tutorial

Watch video tutorial on How To Center Align HTML Table.

Social Media Menu with Popup Tooltip using HTML and CSS Horizontal Navigation Menu with HTML and CSS Responsive Sidebar Menu with CSS and JavaScript Cool CSS Button with Hover Animation Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Color Picker Design with HTML CSS and JavaScript Custom Radio Buttons with CSS Engraved HTML Buttons With CSS Neumorphic Buttons Design with CSS Cool Profile Card Design with HTML CSS Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Simple Price Range Slider With HTML CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Circle With Two Colors using CSS Simple FAQ Accordion With HTML CSS and JavaScript