Changing font-family for placeholder
Asked Answered
J

5

38

Is it posible for an input field to have one font-family and it's placeholder another?

I have tried to change font-family for the input's placeholder with an already defined @font-face in CSS but it's not working:

CSS

    .mainLoginInput::-webkit-input-placeholder { 
      font-family: 'myFont', Arial, Helvetica, sans-serif;
    }
    
    .mainLoginInput:-moz-placeholder { 
      font-family: 'myFont', Arial, Helvetica, sans-serif;
    }

HTML

    <input class="mainLoginInput" type="text" placeholder="Username"  />

How can I solve this problem?

Janes answered 25/1, 2013 at 14:55 Comment(0)
J
5

Found it...

Prefix for Firefox 19+ users is ::-moz-placeholder

And the code looks like this

.mainLoginInput::-moz-placeholder {
   font-family: 'myFont', Arial, Helvetica, sans-serif;  
}
Janes answered 25/1, 2013 at 15:13 Comment(1)
There is also ::-ms-input-placeholder if you support IE 10.Kerriekerrigan
C
69

In case someone want the placeholders selectors for all browsers :

.mainLoginInput::-webkit-input-placeholder {
  font-family: 'myFont', Arial, Helvetica, sans-serif;
}

.mainLoginInput:-ms-input-placeholder {
  font-family: 'myFont', Arial, Helvetica, sans-serif;
}

.mainLoginInput:-moz-placeholder {
  font-family: 'myFont', Arial, Helvetica, sans-serif;
}

.mainLoginInput::-moz-placeholder {
  font-family: 'myFont', Arial, Helvetica, sans-serif;
}
Compress answered 6/5, 2014 at 10:12 Comment(2)
Any reason why -moz-placeholder is added twice? (Maybe I don't understand these single : or double ::.Se
The one with the single : is for firefox v18 and lower. They adopted the double version to follow the webkit semanticCompress
S
10

Use this for major browser support :

HTML:

<input type="text" placeholder="placeholder text.." class="mainLoginInput" />

CSS:

.mainLoginInput::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
  font-family: 'myFont', Arial, Helvetica, sans-serif;
  opacity: 1; /* Firefox */
}

.mainLoginInput:-ms-input-placeholder { /* Internet Explorer 10-11 */
  font-family: 'myFont', Arial, Helvetica, sans-serif;
}

.mainLoginInput::-ms-input-placeholder { /* Microsoft Edge */
  font-family: 'myFont', Arial, Helvetica, sans-serif;
}

Details reference link

Squilgee answered 14/12, 2018 at 9:1 Comment(0)
J
5

Found it...

Prefix for Firefox 19+ users is ::-moz-placeholder

And the code looks like this

.mainLoginInput::-moz-placeholder {
   font-family: 'myFont', Arial, Helvetica, sans-serif;  
}
Janes answered 25/1, 2013 at 15:13 Comment(1)
There is also ::-ms-input-placeholder if you support IE 10.Kerriekerrigan
D
5

Simply like this

.mainLoginInput::placeholder{
     font-family: -Your font here-;
}
Diversify answered 13/6, 2018 at 6:50 Comment(0)
U
2

Here is the complete use of ::placeholder pseudo-element:

::-webkit-input-placeholder { /* Chrome/Opera/Safari */
  color: pink;
}
::-moz-placeholder { /* Firefox 19+ */
 color: pink;
}
:-ms-input-placeholder { /* IE 10+ */
 color: pink;
}
:-moz-placeholder { /* Firefox 18- */
 color: pink;
}

All placeholders in Firefox have an opacity value applied to them, so in order to fix this we need to reset that value:

::-moz-placeholder {
  opacity: 1;
}

Source

Unfavorable answered 2/1, 2017 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.