Skip to content

Instantly share code, notes, and snippets.

@minosiants
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minosiants/9891317 to your computer and use it in GitHub Desktop.
Save minosiants/9891317 to your computer and use it in GitHub Desktop.
How to inline font icons into css

Goal: inline fonts icons to speed up page load

In my case I used only 4 icons from http://fortawesome.github.io/Font-Awesome/ so it's not efficient to include the whole bunch of fortawesome files

  1. At http://fontello.com/ selects required icons and export them.

  2. Encode required font file (.eot .svg .woff .ttf) into base64

Linux example

$ base64 -w0 fontello.woff > fontello.woff.64

  1. Include content of the file in url in @font-face
@font-face {
  font-family: 'FontAwesome';  
  src: url('data:application/x-font-woff;base64, ${filecontent} ') format('woff'),
  url('data:application/x-font-svg;base64, ${filecontent} ') format('svg');
  font-weight: normal;
  font-style: normal;
}
  1. Usage is the same as in exported http://fontello.com/ demo

Result

Only content related to 4 icons is loaded and it's inlined into css or html style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment