Categories
CSS

Using Font-Awesome with Pseudo Elements

Sometimes, you will inject Font Awesome icons into a document using pseudo elements rather than the empty <i> tags that are commonly used.

Here’s example code using Facebook and Twitter.

Note the font family: Font Awesome 5 Brands

.menu-social a::before{
  font-family: "Font Awesome 5 Brands";
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
}
 
.menu-social a.facebook::before {
  content: "\f082";
}
 
.menu-social a.twitter::before {
  content: "\f081";
}
 

For the content value, put a backslash followed by the unicode value. You can find the unicode value in the same place you would find the <i> tag to copy on the Font Awesome website.

A couple of poorly documented variations are required if you are using other types of Font Awesome icons.

Symbol TypeFont FamilyFont Weight
BrandsFont Awesome 5 Brands400
SolidsFont Awesome 5 Solid900
LightFont Awesome 5 Light300