12.02.2021 ... Angular 15 or later: Copy .mat-mdc-cell { vertical-align: top; }. Before Angular 15: Copy .mat-cell { vertical-align: top; }....
Aligning data in a MatTable, a powerful component in Angular Material, can sometimes be a challenge, especially when dealing with vertical alignment. By default, MatTable aligns content to the top of each cell, but what if you need to align text to the middle or bottom? This article will guide you through achieving vertical alignment in a MatTable using CSS.
Before diving into vertical alignment, it's crucial to understand MatTable's default behavior. MatTable uses the CSS `display: table` and `display: table-cell` properties, which align content to the top by default. This is why you might see text aligned to the top of each cell, even when you've added padding or set a cell's height.
To align text to the middle of a cell, you can use the `vertical-align: middle` CSS property. However, this property only works when the cell's height is explicitly set. Here's how you can do it:

```html
| Name | Middle aligned text |
|---|
For more control over vertical alignment, you can use Flexbox. First, set the cell's display property to `flex`, then use the `align-items` property to align the content. Here's an example:
```css td.mat-cell { display: flex; align-items: center; /* Align content to the middle */ } ```
Aligning text to the bottom is similar to aligning it to the middle, but you'll use `align-items: flex-end` instead. Here's an example:
```css td.mat-cell { display: flex; align-items: flex-end; /* Align content to the bottom */ } ```
When dealing with multi-line text, you might need to adjust the cell's height to accommodate the text. You can do this by setting the cell's height to `auto` and using the `line-clamp` CSS property to limit the number of lines. Here's an example:

```css td.mat-cell { height: auto; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; } ```
Remember, using `line-clamp` requires a prefix for different browsers. The example above uses the WebKit prefix for Chrome and Safari.
Aligning text vertically in a MatTable can be achieved using CSS. Whether you're aligning text to the middle, bottom, or dealing with multi-line text, understanding how to use CSS properties like `vertical-align`, `align-items`, and `line-clamp` can help you create more visually appealing tables in your Angular Material applications.
<strong>How do I align mat-table/table content to the top of the cell?</strong><p>12.02.2021 ... Angular 15 or later: Copy .mat-mdc-cell { vertical-align: top; }. Before Angular 15: Copy .mat-cell { vertical-align: top; }.</p>
<strong>Vertical alignment · Material - Daemonite</strong><p>Easily change the vertical alignment of inline, inline-block, inline-table, and table cell elements. Change the alignment of elements with the vertical- ...</p>
<strong>Angular Material Table cannot center columns · Issue #14803 - GitHub</strong><p>By these images I mean what I am trying to achieve and that is merely a centering of the columns. I have given a link to a StackBlitz demo, which is the one ...</p>
<strong>Aligning content in columns & adding custom width with Angular</strong><p>22.09.2020 ... How to Align Text in columns of data-table ... For Data-Tables using Component Elements as shown below: <mat-table [dataSource]="dataList" class=" ...</p>
<strong>[Table] Columns get misaligned in dense tables · Issue #6058 - GitHub</strong><p>26.07.2017 ... ... mat-row { display: table-row; > .mat-header-cell, > .mat-cell { display: table-cell; height: 48px; vertical-align: middle; } } }.</p>
<strong>Angular 8中Mat-Table实现两行表头的问题求助 - 火山引擎</strong><p>06.05.2026 ... ... vertical-align: middle; text-align: center; } .ng-hide { display ... Mat-Table的 *matHeaderRowDef 指令是基于单个 displayedColumns 数组 ...</p>
<strong>Vertical positioning of cell content inside a tabular environment (top ...</strong><p>29.06.2022 ... ... table, is aligned with the row's baseline. But why are you using a ... That means the vertical center of its contents are aligned with ...</p>
<strong>text-align CSS property - MDN Web Docs - Mozilla</strong><p>20.04.2026 ... ... table-cell box. This means it works like vertical-align but in the horizontal direction. In this article. Try it; Syntax; Accessibility; Formal ...</p>
<strong>Any way to center material form fields? : r/Angular2 - Reddit</strong><p>27.01.2023 ... Before I updated to angular/material v15, I was able to center the text and the labels of form fields by using text-align: center. But now, it ...</p>
<strong>Align Items - MudBlazor</strong><p>Blazor Component Library based on Material Design. MudBlazor is easy to use and extend, especially for .NET devs because it uses almost no Javascript.</p>
<strong>CSS display:table, table-row, table-cell - Mediaevent</strong><p>14.01.2024 ... vertical-align: top. display: table-cell top. Bear claw gingerbread gummi bears marshmallow jujubes sesame snaps cheesecake jelly. Take toffee ...</p>
<strong>Align Items - MudBlazor</strong><p>Blazor Component Library based on Material Design. MudBlazor is easy to use and extend, especially for .NET devs because it uses almost no Javascript.</p>
<strong>Layout > Child Alignment - Angular Material</strong><p>layout="column" layout-align="center end" would make children align along the center vertically and along the end (right) horizontally. API, Sets child ...</p>
<strong>Vertical alignment - Bootstrap</strong><p>Easily change the vertical alignment of inline, inline-block, inline-table, and table cell elements. Change the alignment of elements with the vertical- ...</p>
<strong>Angular Material UI Component Library</strong><p>UI component infrastructure and Material Design components for mobile and desktop Angular web applications.</p>
<strong>Scrollable Table in Angular Material | by Dinesh Kumar R - Medium</strong><p>21.04.2020 ... vertical-align: middle; } }. You can reorder the above CSS in your ... <table mat-table [dataSource]="dataSource"> <!-- Your Columns ...</p>
<strong>How to align text vertically with cap-height in a multi-column textbox?</strong><p>06.05.2024 ... Using a table, merge the first column rows and vertically center your glyph ... May be an image of text that says "mat-nav-list a { · Daniel ...</p>
<strong>Automatic Line Breaking — MathJax 4.0 documentation</strong><p>Previous versions of MathJax include \vcenter{} for vertical centering, and v4 adds \vtop{} and \vbox{} for material to be aligned on the top line or bottom ...</p>
<strong>Angular Tables with Bootstrap - free examples & tutorial</strong><p>Responsive Tables built with Bootstrap 5, Angular and Material Design ... This cell inherits vertical-align: bottom; from the table row, This cell ...</p>
<strong>Material Icon And Text Alignment - StackBlitz</strong><p>Starter project for Angular apps that exports to the Angular CLI.</p>