Search
Close this search box.
Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Height and Width
0/1
CSS Margins and Paddings
0/2
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Max-Width Property
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Forms
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

Table Cell Alignment (vertical-align for table cells):

Definition:

Table cell alignment using the vertical-align property is a CSS technique used to control the vertical alignment of content within individual cells of an HTML table. This property is applied to the content within a <td> (table cell) or <th> (table header) element.

Syntax:

td, th {
vertical-align: value;
}

  • The vertical-align property is applied to table cells (td) and table headers (th).
  • The value can be one of the following: baseline, top, middle, bottom, text-top, text-bottom, or a length value.

Example:

HTML
<!DOCTYPE html>
<html lang="en">

<head>
     
    <meta charset="UTF-8">
     
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <style>
        table {
            width: 300px;
            border-collapse: collapse;
            margin: auto;
        }
        th,
        td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
    </style>
      <title>Table Cell Alignment Example</title>
</head>

<body>
      <table>
            <tr>
                  <th>Header 1</th>
                  <th>Header 2</th>
                  <th>Header 3</th>
                </tr>
            <tr>
                  <td>Row 1, Cell 1</td>
                  <td>Row 1, Cell 2</td>
                  <td>Row 1, Cell 3</td>
                </tr>
            <tr>
                  <td>Row 2, Cell 1</td>
                  <td>Row 2, Cell 2</td>
                  <td>Row 2, Cell 3</td>
                </tr>
          </table>




</body>

</html>

Output: