I want to add FontAwesome icon to input placeholder.
So I tried to write code like this.
[html]
<input type="text" placeholder=""/>
[css]
font-family:'Font Awesome 5 Brands' !important
It works fine. Youtube icon is in the input tag.
But When I add search icon(placeholder=""
) into the placeholder, It doesn't work properly.
What is the problem of my code?
Font awesome cheatsheet is here -> https://fontawesome.com/cheatsheet
Thanks.
Use placeholder="" in your input. You can find unicode in FontAwesome page http://fontawesome.io/icons/ . But you have to make sure add style="font-family: FontAwesome;" in your input. Save this answer.
The font-awesome icon can be placed by using the fa prefix before the icon's name. Example: In this example, we will take a form where the input field is necessary. After that, we will place the font-awesome icon inside the input field. We will use the CDN link to use the font-awesome icons.
Well, it is not possible to add an icon to a placeholder of an input field. You can only enter text.
To increase icon sizes relative to their container, use the fa-lg (33% increase), fa-2x , fa-3x , fa-4x , or fa-5x classes. If your icons are getting chopped off on top and bottom, make sure you have sufficient line-height.
Set the font-family
as below, but also set the font-weight
according to which style you want to load. For Solid, the font-weight
would be 900
.
input {
font-family: "Font Awesome 5 Free";
font-weight: 900;
}
Here's a working CodePen to demonstrate.
This does require that you're properly loading Font Awesome 5, and it will only work in the Webfonts with CSS method. In the CodePen example, only Font Awesome Free Solid is being loaded.
Here's a reference showing the font weights associated with each Font Awesome style.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With