Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font Awesome5 with input placeholder

I want to add FontAwesome icon to input placeholder.

So I tried to write code like this.

[html]

<input type="text" placeholder="&#xF167;"/>

[css]

font-family:'Font Awesome 5 Brands' !important

It works fine. Youtube icon is in the input tag.

enter image description here

But When I add search icon(placeholder="&#xF002;") into the placeholder, It doesn't work properly.

enter image description here

What is the problem of my code?

Font awesome cheatsheet is here -> https://fontawesome.com/cheatsheet

Thanks.

like image 994
Hide Avatar asked May 24 '18 05:05

Hide


People also ask

How do I use placeholder font awesome?

Use placeholder="&#xF002;" 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.

How do I add font awesome to the input field?

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.

Can I put icon in placeholder?

Well, it is not possible to add an icon to a placeholder of an input field. You can only enter text.

How to set size of Font Awesome icons?

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.


1 Answers

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.

like image 52
mwilkerson Avatar answered Nov 15 '22 06:11

mwilkerson