Is it possible to use Font Awesome Icon in a Placeholder? I read where HTML isn't allowed in a placeholder. Is there a workaround?
placeholder="<i class='icon-search'></i>"
Is it possible to use Font Awesome Icon in a Placeholder? I read where HTML isn't allowed in a placeholder. Is there a workaround?
placeholder="<i class='icon-search'></i>"
Use
placeholder=""
in your input. You can find unicode in FontAwesome page http://fontawesome.io/icons/ . But you have to make sure addstyle="font-family: FontAwesome;"
in your input.You can't add an icon and text because you can't apply a different font to part of a placeholder, however, if you are satisfied with just an icon then it can work. The FontAwesome icons are just characters with a custom font (you can look at the FontAwesome Cheatsheet for the escaped Unicode character in the
content
rule. In the less source code it's found in variables.less The challenge would be to swap the fonts when the input is not empty. Combine it with jQuery like this.With this CSS:
And this (simple) jQuery
The transition between fonts will not be smooth, however.
Ignoring the jQuery this can be done using
::placeholder
of an input element.The css part
THE BEST PART: You can have different font family for placeholder and text
I solved with this method:
In the CSS I used this code for the fontAwesome class:
In the HTML I have added the fontawesome class and the fontawesome icon code inside the placeholder:
You can see in CodePen.