Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material Tab Component - How to change label font size

I'm using the Angular Material tabs component. Using an example straight from the official docs...

<mat-tab-group>
  <mat-tab label="First"> Content 1 </mat-tab>
  <mat-tab label="Second"> Content 2 </mat-tab>
  <mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>

Everything works fine except that the font size in the tab labels is smaller than I would like and I can't seem to figure out how to make it bigger. I've tried multiple things in CSS but clearly I'm missing something. If someone could help it would be greatly appreciated.

like image 754
Artemis J Avatar asked Oct 31 '25 14:10

Artemis J


2 Answers

in styles.css (Correct by @Marshal)

.mat-tab-label{
    font-size: 10px !important;
 } 

Or you can use the following in component CSS

::ng-deep .mat-tab-label .mat-tab-label-content {
    font-size: x-large;
}

In CSS we can declare style rules like! Important to make the priority on style rules that can be found before

EDITED 2021

Is better use ViewEncapsulation

import { ViewEncapsulation } from '@angular/core';
// ...
@Component({
    // ...
    encapsulation: ViewEncapsulation.None,
})

and in the .scss file.

.content { 
   .mat-tab-label{
     font-size: 10px;
   } 
}

Be careful, as Angular Material says:

Turn view encapsulation off on your component. If you do this, be sure to scope your styles appropriately, or else you may end up incidentally targeting other components elsewhere in your application.

https://material.angular.io/guide/customizing-component-styles

like image 193
Guiditox Avatar answered Nov 03 '25 07:11

Guiditox


To change the tab label font, in global styles.scss

div .mat-mdc-tab {
  font-size: 16px;
}
like image 34
Arve Klev Avatar answered Nov 03 '25 07:11

Arve Klev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!