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>"
If you can / want to use Bootstrap the solution would be input-groups:
Looks about like this:input with text-prepend and search symbol
If you're using
FontAwesome 4.7
this should be enough:A list of hex codes can be found in the Font Awesome cheatsheet. However, in the lastest FontAwesome 5.0 this method does not work (even if you use the CSS approach combined with the updated
font-family
).@Elli's answer can work in FontAwesome 5, but it requires using the correct font name and using the specific CSS for the version you want. For example when using FA5 Free, I could not get it to work if I included the all.css, but it worked fine if I included the solid.css:
For FA5 Pro the font name is 'Font Awesome 5 Pro'
I do this by adding
fa-placeholder
class to input text:<input type="text" name="search" class="form-control" placeholder="" />
so, in css just add this:
.fa-placholder { font-family: "FontAwesome"; }
It works well for me.
Update:
To change font while user type in your text input, just add your font after font awesome
.fa-placholder { font-family: "FontAwesome", "Source Sans Pro"; }
I know this question it is very old. But I didn't see any simple answer like I used to use.
You just need to add the
fas
class to the input and put a valid hex in this case
for Font-Awesome's glyph as here<input type="text" class="fas" placeholder="" />
You can find the unicode of each glyph in the official web here.
This is a simple example you don't need css or javascript.
Where supported, you can use the
::input-placeholder
pseudoselector combined with::before
.See an example at:
http://codepen.io/JonFabritius/pen/nHeJg
I was just working on this and came across this article, from which I modified this stuff:
http://davidwalsh.name/html5-placeholder-css