Center Align Table Headings

To center align content in table headings using CSS, set CSS text-align property for the table headings th, with the value center.

The CSS code to set text alignment for table headings to center is showing in the following.

</>
Copy
th {
  text-align: center;
}

Examples

1. Table headings center alignment

In the following example, we take a table with two columns, and three rows; and set the text alignment to center for the table headings.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    th {
      text-align: center;
    }
    table, th, td {
      border: 1px solid;
      border-collapse: collapse;
      padding: 10px;
    }
    td {
      min-width: 150px;
    }
  </style>
</head>
<body>
  <table>
    <thead>
      <tr>
        <th>Fruit</th>
        <th>Quantity</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Apple</td>
        <td>32</td>
      </tr>
      <tr>
        <td>Banana</td>
        <td>48</td>
      </tr>
      <tr>
        <td>Cherry</td>
        <td>75</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

Conclusion

In this CSS Tutorial, we learned how to use CSS text-align property to center align content in the table headings, with examples.