Use Font Awesome (5) icon in input placeholder text

Thomas Lindauer picture Thomas Lindauer · Apr 27, 2018 · Viewed 9.4k times · Source

I've come across many ways to solve this using Font Awesome < 5, but I can't seem to solve this in any way using Font Awesome 5.

This is how many resources point to adding a Font Awesome icon in placeholder text.

<input style="font-family:FontAwesome !important" type="text" placeholder="&#xf167">

Answer

Thomas Lindauer picture Thomas Lindauer · Apr 27, 2018

Remember to not use the general "Font Awesome 5" font family, you need to specifically end with the branch of icons you're working with. Here i am working the "Brands" category.

<input style="font-family:'Font Awesome 5 Brands' !important" type="text" placeholder="&#xf167">

For a more sophisticated solution you could implement a class that works specifically on the placeholder text of a class like this and add that class to you input. Useful if you want a different font-family on your input values.

.useFontAwesomeFamily::-webkit-input-placeholder { /* WebKit, Blink, Edge */
    font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
    font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily::-moz-placeholder { /* Mozilla Firefox 19+ */
    font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily:-ms-input-placeholder { /* Internet Explorer 10-11 */
    font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily::-ms-input-placeholder { /* Microsoft Edge */
    font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily::placeholder { /* Most modern browsers */
    font-family: "Font Awesome 5 Brands" !important;
}

And then add this class to your tag.

<input class="useFontAwesomeFamily" type="text" placeholder="&#xf167;">