Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change css of asterick generated by required in angular material form field?

I am using angular material in angular6 app.

        <mat-form-field fxFlex>
            <mat-label [class.form-label]="fg.get('email').valid && fg.get('email').touched">{{attributesLabels.email}}</mat-label>
            <input matInput formControlName="email" required [autofocus]="true">
            <mat-error *ngIf="fg.get('email').hasError('required')">Email is required</mat-error>
            <mat-error *ngIf="fg.get('email').hasError('email') && !fg.get('email').hasError('required') ">Invalid email</mat-error>
        </mat-form-field>

This is required field and in the placeholder of this input field, "*" is append after placeholder like below: enter image description here

I want to change the color of "*" in the placeholder to red. How can i change the color?

Html Generated by the above mat-form-field:

enter image description here

like image 729
Johar Zaman Avatar asked Nov 14 '25 13:11

Johar Zaman


1 Answers

This super simple thing for me was at the root of the project in styles.scss just put

.mat-form-field-required-marker { color: red }
like image 116
Robbie Smith Avatar answered Nov 17 '25 10:11

Robbie Smith



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!