How to fix the @font-face flicker issue in FireFox
I’ve been using @font-face more and more over the past couple of months as a way to use custom fonts on websites I manage, but the issue I keep running into is that the contents of the page (including background sprites) will flicker a second after the content has loaded. It’s really ugly.
The best solution that I have found for solving this issue is one published by Paul Irish (in Fighting the @font-face FOUT).
Drop this snippet of javascript in your JS. It targets FireFox 3.5+ and takes care of automatically hiding all page contents until the fonts are loaded and ready to be rendered.
Instead of a flicker, the user will just see a blank page for that half second and then a fully rendered page with all custom fonts embedded. I’ve not tried Google’s Web Font API or Directory, but their homepage (which is supposedly using the web font api) flickers in Firefox – so I’m not sure it works all that well.
Here’s the javascript I use to solve the flicker issue:
1 2 3 4 5 6 7 8 9 10 11 | (function(){ // if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT var d = document, e = d.documentElement, s = d.createElement('style'); if (e.style.MozTransform === ''){ // gecko 1.9.1 inference s.textContent = 'body{visibility:hidden}'; e.firstChild.appendChild(s); function f(){ s.parentNode && s.parentNode.removeChild(s); } addEventListener('load',f,false); setTimeout(f,3000); } })(); |
Enjoy this Post?
Spread the word by promoting this post on FaceBook and Twitter.

thumbs up – thanks for sharing
Cheers, worked perfectly. Thank you!
Works great…
Great script – worked perfectly
You’re a life-saver! I’ve been dealing with this problem for a while and now my sites work perfectly. Thanks.
Thank you so much for this little code snippet. Works like a charm and everything is now smooth in ff 3.5. Keep up the good work and thanks again, Alex
I use webfont loader by google (http://code.google.com/apis/webfonts/docs/webfont_loader.html), it’s work perfect also and more simple in my opinion