Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font awesome shows Squares until it is loaded

I'm using font awesome like so:

<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
  <script src="https://use.fontawesome.com/xxxxxxxx.js"></script>

and an element

However the font doesn't load immediately, and I see ugly squares in the meantime before its loaded. Any way round this?

enter image description here

like image 595
SuperUberDuper Avatar asked Nov 04 '25 05:11

SuperUberDuper


1 Answers

You're experiencing FOUT (flash of unstyled text) as Font Awesome uses fonts to display their icons. Until the font is loaded you'll see the icon in a fallback font (for instance Arial). You see the box because Font Awesome uses Unicode PUA codepoints to map their icons to, and the fallback font has no characters there and will show the generic "missing character" box.

A solution would be to use FontFaceObserver to hide the icons until the Font Awesome font has loaded. Even better would be to use SVG images, as icon fonts are kind of a hack. Font Awesome provides them, so this might be an option for you.

like image 74
RoelN Avatar answered Nov 07 '25 16:11

RoelN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!