HTML Table Align – A Complete Guide with Examples and Best Practices

Table alignment plays a major role in readability and presentation of data.
Properly aligned tables make information easier to scan, understand, and compare.

You commonly need table alignment when working with:

  • Student mark sheets

  • Pricing tables

  • Reports and dashboards

  • Admin panels

  • Data comparison tables

 

As a beginner, it’s important to know that modern HTML uses CSS for alignment, not old HTML attributes.

Important Beginner Rule

  • Avoid old HTML attributes like align="center"
  • Use CSS for table alignment (industry standard)

Types of Alignment in HTML Tables

There are three main types of alignment you should understand:

  1. Aligning the table itself

  2. Aligning text inside table cells

  3. Vertical alignment inside cells

Aligning the Table (Left, Center, Right)

Center Align the Table (Recommended Method)

 
table { margin: auto; }

Complete Example

<table class="center-table">
  <tr>
    <th>Name</th>
    <th>Marks</th>
  </tr>
  <tr>
    <td>Amit</td>
    <td>90</td>
  </tr>
</table>
<!-- css file -->
.center-table {
  margin: auto;
  border-collapse: collapse;
}

This places the table in the center of the page

Left or Right Align the Table

 .left-table {
margin-left: 0;
}

 

.right-table {
margin-left: auto;
}

Aligning Text Inside Table Cells (Horizontal Alignment)

Text inside <th> and <td> can be aligned using text-align.

Center Text in Table Cells

 
th, td { text-align: center; }

Left or Right Align Text

 
th { text-align: left; } td { text-align: right; }

Example

<table>
  <tr>
    <th>Product</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>Laptop</td>
    <td>50000</td>
  </tr>
</table>

css

td {
  text-align: center;
}

Vertical Alignment Inside Table Cells

Vertical alignment controls how content is positioned top, middle, or bottom inside a cell.

CSS Vertical Alignment Values

  • top

  • middle

  • bottom

Example

 
td {
vertical-align: middle;
}

Complete Example

<table>
  <tr>
    <th>Item</th>
    <th>Description</th>
  </tr>
  <tr>
    <td>Book</td>
    <td style="height:80px;">Long description text</td>
  </tr>
</table>
<!-- css-->
td {
  vertical-align: middle;
}


Old HTML table Alignment Methods (Do NOT Use)

<table align="center">
<td align="center">
  • Deprecated
  •  Poor accessibility
  •  Not SEO-friendly

Real-World Example: Aligned Student Table

<table class="student-table">
  <tr>
    <th>Name</th>
    <th>Subject</th>
    <th>Marks</th>
  </tr>
  <tr>
    <td>Riya</td>
    <td>Math</td>
    <td>95</td>
  </tr>
</table>

css

.student-table {
  margin: auto;
  border-collapse: collapse;
}

.student-table th,
.student-table td {
  border: 1px solid #333;
  padding: 10px;
  text-align: center;
}

Common Beginner Mistakes

  • Using align attribute
  • Confusing table alignment with text alignment
  •  Forgetting border-collapse
  •  Aligning only <table> but not <td>
  • Mixing inline styles and CSS unnecessarily

Best Practices (Industry Standard)

  • Always use CSS
  • Center tables using margin: auto
  • Use text-align for text alignment
  • Use vertical-align for vertical positioning
  • Keep styling in external CSS

FAQs: HTML Table Align

How do I center an HTML table?

 
table { margin: auto; }

How do I center text inside table cells?

 
td { text-align: center; }

Is align="center" still supported?

It works in some browsers but is deprecated and not recommended.

How do I vertically center text in a table cell?

 
td { vertical-align: middle; }

Read More

How to Create Database in MySQL

  • By admin
  • November 27, 2021
  • 52 views
How to Create Database in MySQL

How to create table in MySQL

  • By admin
  • November 6, 2021
  • 45 views
How to create table in MySQL

MySQL commands with examples

  • By admin
  • September 11, 2021
  • 118 views
MySQL commands with examples

MySQL use database

  • By admin
  • May 28, 2021
  • 44 views
MySQL use database

System Software

  • By admin
  • May 20, 2021
  • 53 views

Introduction to software

  • By admin
  • May 13, 2021
  • 49 views
Introduction to software