#035: Preventing Typekit FOUT

(Updated on )

We take a little break from working on search to solve a little niggling issue.

“FOUT” being “Flash of Unstyled Text”. This is phenomenon where @font-face fonts take a little bit to load and thus you see the fallback font before the custom font. This is normally not a problem in Typekit. Nor is it really a problem in modern browsers these days (except IE 9). However, it is a problem for us because we’ve specifically chosen to load the Typekit JavaScript asynchronously.

Hope is not lost though, Typekit has this problem covered, we just need to do a smidge of work on our site. We put a new class name on the <html> element called “wf-loading” (web font loading). Then in our CSS, we declare that any selector that uses a custom font is visibly hidden until that class name goes away. A little risky you might think, but if the font fails to load there is a timeout that removes the class anyway. This is just for fighting FOUT remember, just a little visual nicety.

We do all this by making a little Sass @mixin called “preventFOUT” and @include-ing it in our custom font stacks, which are also @mixins.

This works well for us now. Ultimately in this design we move over to HF&J fonts in which load directly via @font-face so we basically stop worrying about this.