CSS – Vertical Align Content in Table Cells to Middle

To align the content in table cells in the middle along vertical axis using CSS, set CSS vertical-align property for the table cells td with the value middle.

The CSS code to set vertical alignment for table cells to middle is showing in the following.

</>
Copy
td {
  vertical-align: middle;
}

Examples

1. Align table contents to middle

In the following example, we take a table with two columns, and three rows; and set the vertical alignment of content in table cells to middle.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    td {
      height: 50px;
      vertical-align: middle;
    }
    table, th, td {
      border: 1px solid;
      border-collapse: collapse;
      padding: 10px;
    }
  </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 vertical-align property to vertically align content in the table cells in the middle, with examples.