How to make only placeholder italics in input

prabin badyakar picture prabin badyakar · Dec 25, 2014 · Viewed 50.5k times · Source

Hi can any one tell me how can i make only placeholder italics but when someone writes inside a test box , written word shouldnt have italics.

MyCode:

<input type="text" id="search" placeholder="Search" style="font-style:italic">

How can i place italic on only placeholder not whole input???

Answer

Joseph Marikle picture Joseph Marikle · Dec 25, 2014

Sure. Just apply the style to these CSS rules:

::-webkit-input-placeholder {
   font-style: italic;
}
:-moz-placeholder {
   font-style: italic;  
}
::-moz-placeholder {
   font-style: italic;  
}
:-ms-input-placeholder {  
   font-style: italic; 
}

Probably not all of these rules are needed. I always just reference CSS Tricks because I always forget how to do it.

Edit: Note that these rules cannot be combined into one selector. They must be declared separately as noted by Dave Kennedy in the comments below.