How Do You Style an Angular Material Table? [Closed]

How Do You Style an Angular Material Table? [Closed]

I need some help with styling an angular material table. How do yous style the headers and the cells?

This is my app.component.html:

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
  <ng-container matColumnDef="name">
    <th mat-header-cell *matHeaderCellDef>Name</th>
    <td mat-cell *matCellDef="let element">{{ element.name }}</td>
  </ng-container>
  <ng-container matColumnDef="rating">
    <th mat-header-cell *matHeaderCellDef>Rating</th>
    <td mat-cell *matCellDef="let element">{{ element.rating }}</td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
1

1 Answer

You can apply css on mat-header-cell for header style and mat-cell for data cell.

.mat-header-cell {
  color: red;
}

.mat-cell {
  color: blue;
}

See the Stackblitz

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.