Search code examples
cssangularjs-material

How do I change md-input-container placeholder color using css in angular material?


How do I change md-input-container placeholder color using css in Angular Material? As screenshot below I have phone no. and password textfield. Phone no. textfield has Phone No. and password has Password placeholder name.

enter image description here


Solution

  • Placeholder is depicted as a <label> in Angular Material. So you actually need to style the label not the placeholder.

    As soon as you click (focus) on the input this <label> which is looking as a placeholder slides up and converted into a form <label>.

    So you just need to apply this CSS:

    /* When the input is not focused */
    md-input-container label {
      color: red;
    }
    
    /* When the input is focused */
    md-input-container.md-input-focused label {
      color: blue;
    }
    

    Have a look at this Plunkr Demo.