Search code examples
cssangularinputsassmat-form-field

How to add letter-spacing to input value but not to input placeholder (Angular 11)


I have a mat-form-field in my Angular project in which I need to add letter-spacing to the input value but not the input placeholder.

Currently, my input looks like this:

mat-form-field input placeholder

And when user types something in the input, it looks like this:

mat-form-field input value

What I want, is for the input placeholder to look like this (without any letter spacing), but keep input value's letter spacing at the same time:

mat-form-field input placeholder

Is there any possible way to do this?

This is my HTML:

    <mat-form-field
      id="mobileNumber"
      appearance="outline"
    >
      <span matSuffix>+98</span>
      <input
        type="text"
        matInput
        name="mobileNumber"
        formControlName="mobileNumber"
        placeholder="Mobile Number"
      />
    </mat-form-field>

And this is my SCSS:

     mat-form-field#mobileNumber {
        width: 70%;

        ::ng-deep .mat-form-field-wrapper,
        .mat-form-field-wrapper {
          ::ng-deep .mat-form-field-infix {
            direction: ltr;
            text-align: center;

            ::ng-deep input {
              letter-spacing: 8px;
            }
          }
        }
      }

Solution

  • ::placeholder /* Chrome, Firefox, Opera, Safari 10.1+ */
    :-ms-input-placeholder /* Internet Explorer 10-11 */
    ::-ms-input-placeholder /* Microsoft Edge */
    

    With this, you can style the placeholder